Nitish Kumar
Nitish Kumar

Reputation: 6276

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

Upvotes: 8

Views: 46325

Answers (5)

Aashir Azeem
Aashir Azeem

Reputation: 169

Below code will work.

<a href="{{ route('/cardetails', ['121','cars'] ) }}">click </a>

In URL it will be like this below line.

127.0.0.1:8000/cardetails/121/cars

Upvotes: 1

Neeraj Tangariya
Neeraj Tangariya

Reputation: 1407

In your route put name and

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

Go to your html where you link the url

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

Upvotes: 1

ClearBoth
ClearBoth

Reputation: 2325

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

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

In templates:

{{ route('dashboard').'#something' }}

Upvotes: 16

Atiqur
Atiqur

Reputation: 4022

Lets say you have route like these....

Route::get('/nitsadmin/dashboard', function () {
    return view('nitsadmin.dashboard');
});
Route::get('/land', 'HomeController@landingPage');
Route::get('/role-permission/add',          ['as' => 'mp.rp.add',          'uses' => 'RolePermissionMapController@add']);

so you can link like this --

<a href="{{url('/nitsadmin/dashboard')}}">Click </a>
<a href="{{url('/land')}}">Click </a>
<a href="{{url('/role-permission/add')}}">Click </a>
<a href="{{route('mp.rp.add')}}">Click </a>

Upvotes: 1

James
James

Reputation: 16339

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.

Upvotes: 13

Related Questions