Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 - Blade Templating - How to properly Link to Route?

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?

like image 591
LoveAndHappiness Avatar asked Mar 31 '14 00:03

LoveAndHappiness


4 Answers

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>
like image 119
Joseph Silber Avatar answered Nov 06 '22 05:11

Joseph Silber


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)

like image 24
Alejandro Silva Avatar answered Nov 06 '22 04:11

Alejandro Silva


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>
like image 5
Hamid Naghipour Avatar answered Nov 06 '22 03:11

Hamid Naghipour


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)) }}
like image 3
Govind Samrow Avatar answered Nov 06 '22 04:11

Govind Samrow