我正在使用Laravel 6.2。我有一个命名路线
Route::get('/dummy/{id}', 'ApiV1DummyDataController@show')->name('dummy_data_show');
我无法为它编写测试,我收到错误IlluminateRoutingExceptionsUrlGenerationException: Missing required parameters for [Route: dummy_data_show] [URI: api/v1/dummy/{id}].
这些是我的尝试(仅相关代码(:
$request = $this->withHeaders(
[
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$token,
]
)->json('GET',
Route('dummy_data_show'),
[
'id' => 1,
]
);
还有
$request = $this->withHeaders(
[
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$token,
]
)->json('GET',
Route('dummy_data_show'),
1
);
当然,如果我尝试
$request = $this->withHeaders(
[
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$token,
]
)->json('api/v1/dummy/1');
我没有收到错误。我的错误是什么?谢谢!
您没有将任何参数传递给route
方法。参数应位于括号内。
改变:
Route('dummy_data_show'),
[
'id' => 1,
]
自:
route('dummy_data_show', [
'id' => 1,
])