How to put route in anchor tag in laravel 5.2

时间秒杀一切 提交于 2019-11-28 01:02:05

问题


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:


回答1:


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.




回答2:


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

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

In templates:

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



回答3:


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>



回答4:


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>


来源:https://stackoverflow.com/questions/37695864/how-to-put-route-in-anchor-tag-in-laravel-5-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!