【问题标题】:i want to use dynamic id and company name in my url using routes in laravel 5我想使用 laravel 5 中的路由在我的 url 中使用动态 id 和公司名称
【发布时间】:2016-09-16 00:59:55
【问题描述】:

我可以使用 laravel 5 在 url 中使用动态 id 和公司名称吗,例如 我的网址是 http://beta.simplesign.se/12/textpress 12 和 textpress 可以是动态的我试过这个 Route::get('/{id}/{name}', function ($id, $name) {

Route::controller('/'.$id.'/'.$name.'/','onlinecontractController'); });

但这会在 ControllerInspector.php 中显示 ReflectionException

【问题讨论】:

    标签: laravel url dynamic routes


    【解决方案1】:

    只需像这样设置您的路线:

    Route::get('{id}/{name}', ['uses' => 'YourController@show']);
    

    并像这样在你的控制器上添加一个名为 show 的函数:

    public function show($id, $name) {
        print_r($id . ' ' . $name);
    }
    

    【讨论】:

      【解决方案2】:

      你的路线将是

      Route::get('{id}/{name}', 'YourController@yourMethod');
      

      然后你的控制器方法将是

      public function yourMethod($id, $name){
      //now you can die and dump dynamic id and name here
      dd($id, $name);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-12-05
        • 2017-04-01
        • 2015-03-06
        • 2020-08-06
        • 2023-03-20
        • 2023-01-04
        • 2015-10-26
        • 2013-12-30
        相关资源
        最近更新 更多