0
votes

I'm viewing table of users from MySQL database using laravel,andhow there is edit column and I need to use the $id parameter to redirect the user to another page and view the user details. this is my route and it's working fine.

<td>
    <a href="{{ URL::to('userdetails',$user->id) }}"</a>
    Edit
</td>

but after going to this page that view user detials. my navigation bar url's start behaving weird.

when I view the users list my URL is

/osama/warehouse/public/index.php/userslist

when I view a specific users with an id the url is

/osama/warehouse/public/index.php/userdetails/1

until all good, but after that when I click on my home button on my navigation bar or other links I get an error because the URL not correct

/osama/warehouse/public/index.php/userdetails/home !!!

the right URL should be

/osama/warehouse/public/index.php/home 

note I'm not using blade route or html url for my navigation bar,just pure HTML.the reason is I got css classes that I can't include in the html link.

3
Please provide your code for your "Home" button. And could you please elaborate why you are not using Laravel helper classes?Philipe
this is one of my navigation bar code and it's hard to write using blade.<a <?php if ($_SESSION['navbar']=="dashboard"){echo 'class="active"';}?> href="home"><i class="fa fa-dashboard fa-fw"></i> Dashboard</a>Osama Al-Banna

3 Answers

0
votes

You should really use the helper classes that Laravel provides.
This kind of problem would be avoided.

Examples using Laravel:

<a href="{{ URL::to('home') }}">Dashboard</a>
<a href="{{ url('home') }}">Dashboard</a>

If you insist in not using them, you probably have to modify your links to be relative to your root by adding a slash at the beggining:

<a href="/home">Dashboard</a>

You should change all URL's that needs to be relative to your root.

0
votes

URL::to() doesn't prefix the URL with / so when you call it, you'll get "userslist" or "userdetails/1" back.

If you simply put a / into your call to URL::to(), it'll work fine:

<a href="{{ URL::to('/userdetails',$user->id) }}"></a>

You'll need to do this with all occurrences of URL::to() (eg. on your Home link).

In other news, there are a couple of other issues:

  • your <a> tag is missing the close > - you just have id) }}"</a>
  • your link is empty, because "Edit" is outside the tag. You probably want id) }}">Edit</a>
0
votes

thanks guys guys the solution is to change the navigation bar link's {{ url('home') }} this link work everywhere using laravel blade