phplaraveltesting

get route field parameter


When I'm testing get route in Laravel I am getting error that token field is required.

$response = $this->get(route('resendsms', ['token' => $token]));

web route

Route::get('/auth/resendsms/{token}', [AuthController::class, 'resendsms'])->name('resendsms');

I seem not to have the right syntax

What am I doing wrong?

Thank you

Things I tried

$response = $this->get(route('resendsms', ['token' => $token]));
$response = $this->get(route('resendsms',$token));

Solution

  • Follow the example and check the parameters of the AuthController@resendsms method.

    This method was tested by me

    Route::get('/auth/resendsms/{token}', function (string $token) {
        // ...
    })->name('resendsms');
     
    $url = route('resendsms', ['token' => 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9', 'photos' => 'yes']);
    
    $response = $this->get($url);
    
    $response->assertStatus(200);
     
    // $url - /auth/resendsms/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9?photos=yes
    

    Follow the example and check the parameters of the AuthController@resendsms method.

    You can also use the

    $this->call('GET', '/auth/resendsms/{token}');
    

    Also be sure to clear your cache

    php artisan route:clear
    

    I also recommend making parameters of the right type

    })->where(['token' => '[a-zA-Z0-9]+'])->name('resendsms')
    

    Laravel Routing