如何结合这两条路线?
How to combine these two routes?
我有这两条路线:
Route::post('/post',
array(
'uses' => 'PostController@newPost'
)
);
Route::post('/post/picture',
array(
'uses' => 'PostController@newPost'
)
);
在实际的控制器中,我区分了这两个参数(因为他们使用的是同一个控制器),但是如何将上面的两条路由组合起来呢?
试试下面的方法
Route::post('/post/{picture?}',
array(
'uses' => 'PostController@newPost'
)
);
将 picture
包裹在 {}
括号中会将 URL 段视为参数。在参数末尾使用 ?
将其视为可选。一个警告:这也会捕获像
这样的东西
/post/some-other-thing
如果您担心抓不到其他物品,请尝试以下方法
Route::post('/post/{myvar?}',
array(
'uses' => 'PostController@newPost'
)
)->where('myvar','picture');;
where
方法的第二个参数可以是任何 PCRE 正则表达式。
我有这两条路线:
Route::post('/post',
array(
'uses' => 'PostController@newPost'
)
);
Route::post('/post/picture',
array(
'uses' => 'PostController@newPost'
)
);
在实际的控制器中,我区分了这两个参数(因为他们使用的是同一个控制器),但是如何将上面的两条路由组合起来呢?
试试下面的方法
Route::post('/post/{picture?}',
array(
'uses' => 'PostController@newPost'
)
);
将 picture
包裹在 {}
括号中会将 URL 段视为参数。在参数末尾使用 ?
将其视为可选。一个警告:这也会捕获像
/post/some-other-thing
如果您担心抓不到其他物品,请尝试以下方法
Route::post('/post/{myvar?}',
array(
'uses' => 'PostController@newPost'
)
)->where('myvar','picture');;
where
方法的第二个参数可以是任何 PCRE 正则表达式。