如何在Laravel 5.2中使用带后缀的路由

时间:2016-05-05 13:53:21

标签: php laravel-5.2 laravel-routing

我试试

 $suffix = '.test';
 Route::get('article/edit/{name?}'.$suffix, ['uses' => 'ArticleController@edit', 'as' => 'Edit']);

它运作良好。然后我添加了auth组,$ name总是以$ suffix返回(例如:$ name =' abc.test')

 Route::group(['middleware' => 'auth'], function () {
 global $suffix;
       Route::get('article/edit/{name?}'.$suffix, ['uses' => 'ArticleController@edit', 'as' => 'Edit']);
});

但我希望它返回$ name =' abc&#39 ;; 我哪里错了?

1 个答案:

答案 0 :(得分:0)

如果你做了什么?

Route::group(['middleware' => 'auth'], function () {
   global $suffix = '.test';
   Route::get('article/edit/{name?}'.$suffix, [
      'uses' => 'ArticleController@edit',
      'as' => 'Edit'
   ])->where('name', '/[^a-zA-Z0-9_\.-]/');
});