具有参数格式的命名路由

Named route with a parameter format

我已经研究过,但未能找到正确执行此操作的示例。

我需要结合以下内容:

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

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

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

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

像这样定义你的路线

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

并且在您的控制器方法中,您可以使用参数

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