Ad

Illuminate\Routing\Exceptions\UrlGenerationException: Missing Required Parameters For

- 1 answer

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

Route::get('/dummy/{id}', 'Api\V1\[email protected]')->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!

Ad

Answer

You are not passing any parameters to your route method. The parameters should be inside the parenthesis.

Change:

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

To:

route('dummy_data_show', [
    'id' => 1,
])
Ad
source: stackoverflow.com
Ad