0

I'm using Laravel 6.2. I have a named route

Route::get('/dummy/{id}', 'Api\V1\DummyDataController@show')->name('dummy_data_show');

I cannot write the test for it, I get the error Illuminate\Routing\Exceptions\UrlGenerationException: Missing required parameters for [Route: dummy_data_show] [URI: api/v1/dummy/{id}].

These are my attempts (only relevant code):

$request = $this->withHeaders(
            [
                'Accept' => 'application/json',
                'Authorization' => 'Bearer '.$token,
            ]
        )->json('GET',
            Route('dummy_data_show'),
            [
                'id' => 1,
            ]
        );

and also

$request = $this->withHeaders(
            [
                'Accept' => 'application/json',
                'Authorization' => 'Bearer '.$token,
            ]
        )->json('GET',
            Route('dummy_data_show'),
            1
        );

Of course if I try with

$request = $this->withHeaders(
            [
                'Accept' => 'application/json',
                'Authorization' => 'Bearer '.$token,
            ]
        )->json('api/v1/dummy/1');

I don't get the error. What is my error? Thank you!

4

1 回答 1

2

您没有将任何参数传递给您的route方法。参数应该在括号内。

改变:

Route('dummy_data_show'),
[
    'id' => 1,
]

至:

route('dummy_data_show', [
    'id' => 1,
])
于 2019-12-03T18:36:56.817 回答