No need to add the csrf token. Try removing it
Also you it seems wrong that show is a post route? A post route is for storing data, not showing a view. Seems you have mixed up 2 routes
Summer Sale! All accounts are 50% off this week.
Hi - I'm trying to set up a test for a log-in form submission, although I think I'd hit this problem with testing any form. When I run the test I get the error "Illuminate\Session\TokenMismatchException: CSRF token mismatch". For those testing guru's out there: a) am I doing something wrong or b) how do I correctly fake the csrf token ? Here's the test function:
public function test_user_can_log_in()
{
$this->withoutExceptionHandling();
$this->post(uri: action([LoginController::class,'show'],[
'email' => '[email protected]',
'password' => 'password',
'_token' =>csrf_token(),
]))
->assertSuccessful();
}
and the Controller's "show" function:
public function show(Request $request)
{
$inputs = $request->validate(
[
'email' => ['email','required'],
'password' => ['string','required'],
]
);
return view('welcome');
}
Thanks for your help!
Maybe you cached stuff in dev (never cache in dev or testing)
Try
php artisan config:clear
//or
php artisan optimize:clear
Please or to participate in this conversation.