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

前端 未结 6 1510
我在风中等你
我在风中等你 2020-12-15 03:51

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

But in this

相关标签:
6条回答
  • 2020-12-15 04:30

    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>
    
    0 讨论(0)
  • 2020-12-15 04:33

    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)

    0 讨论(0)
  • 2020-12-15 04:36

    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>
    
    0 讨论(0)
  • 2020-12-15 04:40

    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)) }}
    
    0 讨论(0)
  • 2020-12-15 04:44

    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>
    
    0 讨论(0)
  • 2020-12-15 04:46

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

    0 讨论(0)
提交回复
热议问题