Question

I want to create a resourceful link with Laravel. Normally I just use the {{ link_to_route('Yadayadayada.route', 'LinkName', $params }}

But in this case I am using a Template with this layout:

<a href="index.html">
     <i class="icon-dashboard"></i>
     <span class="menu-text"> Dashboard </span>
</a>

That means that inside the anchor tag, is as well a <i>-Tag and a <span>-Tag. Is it possible to use the {{ link_to_route }}-Method, without having to change the layout of the Template?

Was it helpful?

Solution

Use URL::route() to get just a link:

<a href="{{ URL::route('user/profile/', $params) }}">
     <i class="icon-dashboard"></i>
     <span class="menu-text"> Dashboard </span>
</a>

OTHER TIPS

If you Route use a Closure, you can use URL::to(), like this

<a href="{{ URL::to('home/otherpage', $params) }}">
    <i class="icon-dashboard"></i>
    <span class="menu-text"> Dashboard </span>
</a>

As @orrd sugested, in general terms is better to use named routes, so it can be easily change the URL later:

<a href="{{ URL::route('routeName', $params) }}">
    <i class="icon-dashboard"></i>
    <span class="menu-text"> Dashboard </span>
</a>

(ref: https://laravel.com/docs/5.0/helpers#urls)

if you define Route name you can use that in your blade :

 Route::get('/admin/transfer/forms-list', [
    'as'   => 'transfer.formsList',
    'uses' => 'Website\TransferController@IndexTransferForms'
]);

now you can use that in your blade like this :

<a href="{{URL::route('transfer.formsList')}}"  type="submit">
                    discard</a>

There are no of ways to use route in blade:

1. Use Action

{{URL::action('DemoController@index',$params)}}

2. Use Route

{{ URL::route('route/', $params) }}

3. Use URL to

{{ URL::to('route/name', $params)) }}

Use URL::route() to get just a link:

<a href="{{ URL::route('user/profile/', $params) }}">
     <i class="icon-dashboard"></i>
     <span class="menu-text"> Dashboard </span>
</a>

{{ link_to_route('dashboard', 'Dashboard', '', array('class'=>'body')) }}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top