Linking in Laravel Blade Template
Solution 1
HTML::linkAction /
have a look at the docs for more :)
laravel helpers
Solution 2
There are several options. You can use the link_to_action
/ HTML::linkAction
helper if you're linking to a controller's method:
<li>{{ HTML::linkAction('UserController@getFavorites', 'Favorites', ['id' => 5], ['class' => 'abc']) }}</li>
Another option is to link to a named route with link_to_route
/ HTML::linkRoute
:
<li>{{ HTML::linkRoute('user.favorites', 'Favorites', ['id' => 5], ['class' => 'abc']) }}</li>
You can find more information on helpers in the documentation and in the API pages for HtmlBuilder and UrlGenerator.
patrick
Updated on June 07, 2022Comments
-
patrick almost 2 years
I am quite new to Laravel but I've watched quite a lot of tutorials to get into it, so I am used to it now. However, I am stuck at a point where I want to link to a users favorites in one of my blade.php files.
This is the link in my bootstrap navbar:
<li><a href="{{ URL::to('users/' . $user->id . '/favortites' }}"><i class="fa fa-heart"> </i> Favorites</a></li>
I have tried using URL::to but it does not work. I am not sure whether I am implementing the userId correctly.
In the end the link I want to access should look like this: users/5/favorites if the user with an id of 5 is the authenticated user.
I would really appreciate some help here.
Thank you.