【问题标题】:how to pass object parameters using route() method in laravel5.4如何在 laravel5.4 中使用 route() 方法传递对象参数
【发布时间】:2018-11-24 06:24:53
【问题描述】:

我有一个刀片应该将 id 发送到控制器进行排序 我只是想尝试使用简单参数的路线来看看会发生什么但我遇到了错误:(

这是我在刀片中的路由调用

<a href="{{ route('sortby_followers' , ['id' => 8]) }}" > click </a>

这是我的 web.php

 Route::get('/sortby=followers/{id}' , [
    'uses' => 'PageController@sortby_followers',
    'as' => 'sortby_followers'
]);

在控制器代码中

 public function sortby_followers($id)
 {
    dd($id);
 }

但我得到了这个错误

缺少 [Route: sortby_followers] [URI: sortby=followers/ali/ghasem/{id}]。 (看法: C:\wamp64\www\insta\resources\views\admin\r_pages\shop\product.blade.php)

我只是想看看发生了什么,现在我没有使用对象参数进行路由

【问题讨论】:

    标签: laravel routes laravel-5.4


    【解决方案1】:

    试试这个

    使用/sortby_followers/{id} 而不是/sortby=followers/{id} 否则就这样使用

    在这样的刀片使用中

    <a href="{{ route('sortby_followers' , 8) }}">click</a>
    

    在网络中

    Route::get('/sortby_followers/{id}' ,'PageController@sortby_followers');
    

    在控制器中

    public function sortby_followers($id)
    {
        dd($id);
    }
    

    【讨论】:

    • @Rezash 在这里添加兄弟
    【解决方案2】:

    只在web.php更改您的路线

    /sortby=followers/{id}/sortby_followers/{id}

    Route::get('/sortby_followers/{id}' , [
                        'uses' => 'PageController@sortby_followers',
                        'as' => 'sortby_followers'
                      ]);
    

    还要更改您的网络链接:

    <a href="{{route('sortby_followers' , [8])}}" >click</a>
    

    【讨论】:

    • 我已经测试过它对我有用,你还缺少其他东西。再次检查您的路线设置。它应该可以工作。
    猜你喜欢
    • 2012-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多