【问题标题】:Named route with a parameter format带参数格式的命名路由
【发布时间】:2015-07-07 09:26:20
【问题描述】:

我进行了研究,但未能找到如何正确执行此操作的示例。

我需要结合以下内容:

Route::get('self', ['as' => 'self', 'uses' => 'FrontendController@self']);

Route::get('self/{type}', function($type = 'type'){});

【问题讨论】:

  • 为什么需要合并它?
  • 我想使用一个命名的控制器并且有一个参数。
  • Route::get('self/{type?}', ['as' => 'uses' => 'FrontendController@self']);

标签: laravel laravel-5 laravel-routing


【解决方案1】:

这样定义你的路线

Route::get('self/{type?}', ['as' => 'uses' => 'FrontendController@self']);

在你的控制器方法中你可以使用参数

public function self($type = null)
{
// your code
}

【讨论】:

    【解决方案2】:

    您可以使用组前缀来解决它。例如:

     Route::group(['prefix' => 'self'], function()
    {
        Route::get('/','FrontendController@self');
        Route::get('{type}',function($type){
            return $type;
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2013-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-01
      • 2011-12-23
      相关资源
      最近更新 更多