我想使用以下方法在每个组路由之前添加customer_id。customer_id设置为 Session::get('customer.id')。
Route::group(['prefix' => 'customer/{id}'], function($id) {
Route::get('reports/default', array('as' => 'customer_reports_path', 'uses' => 'ReportController@getDefault'))->before('customer');
Route::get('data/objects/{$object_id}', array('as' => 'customer_reports_object', 'uses' => 'DataController@getObject'));
});
第一条路线按方面工作,但是,我不知道如何正确使用第二条路线。
{{ HTML::link(route('customer_reports_object', [Session::get('customer.id'), $object_id], 'Object name') }}
链接仍以 404 结尾。
@MichaelColeman是正确的$
路由参数中不允许使用符号。原因如下:
路由参数由正则表达式找到,该正则表达式仅匹配w
(单词),不包括$
。
IlluminateRoutingRoute@compileRoute
$uri = preg_replace('/{(w+?)?}/', '{$1}', $this->uri);
解决方案显然是删除$
(首先可能是错字)
Route::get('data/objects/{object_id}'...
并正确生成您的链接。(我也建议你使用link_to_route
功能)
{{ link_to_route('customer_reports_object', 'Object name', [Session::get('customer.id'), $object_id]) }}
尝试在参数中没有$
,即
Route::get('data/objects/{object_id}', array('as' => 'customer_reports_object', 'uses' => 'DataController@getObject'));