Using Named URL in blade template

流过昼夜 提交于 2019-12-05 06:16:47

You can use the route() helper, documented here.

<a href="{{ route('new.survey') }}">My Link</a>

If you include laravelcollective/html you could use link_to_route(). This was originally part of the core but removed in Laravel 5. It's explained here

{!! link_to_route('new.survey', 'My Link') !!}

The Laravel Collective have documented the aforementioned helper here. The function prototype is as follows

link_to_route($routeName, $title = null, $parameters = [], $attributes = []);

If for example you wanted to use parameters, it accepts an array of key value pairs which correspond to the named segments in your route URI.

For example, if you had a route

Route::get('surveys/{id}', 'SurveyController@details')->name('detail.survey');

You can generate a link to this route using the following in the parameters.

['id' => $id]

A full example, echoing markup containing an anchor to the named route.

{!! link_to_route('new.survey', 'My Link', ['id' => $id]) !!}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!