8

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

Community
  • 1
  • 1
Nitish Kumar
  • 6,054
  • 21
  • 82
  • 148

5 Answers5

16

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

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

In templates:

{{ route('dashboard').'#something' }}
ClearBoth
  • 2,235
  • 2
  • 18
  • 24
13

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.

James
  • 15,754
  • 12
  • 73
  • 91
  • Thanks, it worked. Before that I was trying `URL::route('nitsadmin/dashboard')` it was not working. – Nitish Kumar Jun 08 '16 at 07:43
  • 3
    {{route('route.name')}} is preferable to this because you aren't hard coding the route and if it changes your links wont change. – Squiggs. Mar 18 '17 at 11:08
  • @Paul very good point. This is one of those "lightbulb moments" for me - I never actually saw the value in using named routes, but this totally makes sense! – James Mar 18 '17 at 11:10
1

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>
Atiqur
  • 3,802
  • 1
  • 25
  • 26
1

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>
Neeraj Tangariya
  • 1,159
  • 1
  • 17
  • 29
1

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

Aashir Azeem
  • 173
  • 6