我生成这样的网址:
URL::action('FieldsController@show',['id' => $field->id, 'head' => cleanUrl($field->head)])
在我的路线中,我有:
Route::get('/field/{head}-{id}', 'FieldsController@show');
它不起作用,只有当我把ID放在第一位且HEAD第二位才这样:
Route::get('/field/{id}-{head}', 'FieldsController@show');
有人有想法吗?我需要在URL
中的HEAD之后获得ID答案 0 :(得分:4)
你不能像
那样做路由{head}-{id}
你需要这样做:
Route::get('/field/{head}/{id}', 'FieldsController@show');
然后在show()
函数中,您可以自己组合它们:
function show($head, $id)
{
$var = $head.'-'.$id;
// do whatever you want with $var here
}