Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put route in anchor tag in laravel 5.2

I've gone through many of the articles below, which explains generating link from named route, but unable to solve my problem.

Tutorial 1

Tutorial 2

Tutorial 3

Following is the defined routes:

Route::get('/nitsadmin/dashboard', function () {
    return view('nitsadmin.dashboard');
});

And I'm calling link in anchor tag:

<a id="index" class="navbar-brand" href="{{Html::linkRoute('/nitsadmin/dashboard')}}">
      <img src="../img/admin/nitseditorlogo.png" alt="Logo">
</a>

I'm getting following error:

enter image description here

like image 875
Nitish Kumar Avatar asked Jun 08 '16 07:06

Nitish Kumar


People also ask

What is route in HREF in Laravel?

Pass multiple variables to anchor tag (href) using url() helper in laravel view. You can pass the multiple variable to url in laravel using url() helper method. To pass the value using $user->id and $user->name variable to URL you have to define web route and get the user details using controller's method.

Which of the following is used to define a global constraint in Laravel?

Global Constraints You can define these patterns in the boot method of your RouteServiceProvider.


2 Answers

For coders using routes names, simply they can use to() method:

return redirect()->to(route('dashboard').'#something');

In templates:

{{ route('dashboard').'#something' }}
like image 127
ClearBoth Avatar answered Oct 13 '22 19:10

ClearBoth


You can do this quite simply with the url() helper.

Just replace your anchor tag like so:

<a id="index" class="navbar-brand" href="{{url('/nitsadmin/dashboard')}}">
      <img src="../img/admin/nitseditorlogo.png" alt="Logo">
</a>

Regarding the image that you have used in there, if these were to be stored in your public folder then you could always use the asset() helper. This would help you turn your absolute links to in dynamic ones.

like image 13
James Avatar answered Oct 13 '22 18:10

James