Illuminate\Routing\Exceptions\UrlGenerationException: 缺少必需的参数
Illuminate\Routing\Exceptions\UrlGenerationException: Missing required parameters for
我正在使用 Laravel 6.2。我有一条命名路线
Route::get('/dummy/{id}', 'Api\V1\DummyDataController@show')->name('dummy_data_show');
我无法为它编写测试,我收到错误 Illuminate\Routing\Exceptions\UrlGenerationException: 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,
])
我正在使用 Laravel 6.2。我有一条命名路线
Route::get('/dummy/{id}', 'Api\V1\DummyDataController@show')->name('dummy_data_show');
我无法为它编写测试,我收到错误 Illuminate\Routing\Exceptions\UrlGenerationException: 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,
])