I am new in Laravel and I am using Laravel 5.5.
When I am submitting without {{ csrf_field() }}
not getting the error Token mismatch exception in Verify csrf token
The error is
The page has expired due to inactivity.
Please refresh and try again
My HTML form is
<form method="POST" action="/post">
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title">
</div>
<div class="form-group">
<label for="textblog">Body</label>
<input type="textarea" class="form-control" name="body">
</div>
<button type="submit" class="btn btn-primary">Publish</button>
</form>
My Route web file
Route::post('/post','PostsController@store');
Here is my Controller class function
public function store() {
dd(request()->all());
}
seems a problem inside laravel. it's showing incorrect message. there are some similar posts: 1stlink, 2ndlink
you should just put your csrfField there and problem will be vanished.
additional links about laravel errors:
Larave 5.5: default error views and costomizing them
Laravel 5.5: set error details via debug
option
As @Shaz said in https://es.stackoverflow.com/questions/99342/laravel-5-5-the-page-has-expired-due-to-inactivity-please-refresh-and-try-aga
In Laravel 5.5, "TokenMismatch" throws an exception with code 419
Update: .. and an error page with the message "The page has expired due to inactivity. Please refresh and try again"
I would recommend installing https://github.com/barryvdh/laravel-debugbar
so you can see the exceptions.
You will probably see
../vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php#70
return $this->addCookieToResponse($request, $next($request));
}
throw new TokenMismatchException;
}
Update:
When I am submitting without {{ csrf_field() }} not getting the error Token mismatch exception in Verify csrf token
You are getting the mismatch exception but with the new error page and code.
(https://laravel-news.com/laravel-5-5-error-views)
The {{ csrf_field() }} creates an input hidden with the token, so you have to use it in your forms ( also check that the token is not empty in the form )
<input type="hidden" name="_token" value="nReVYpjfvqiVVkE8LpGeNOdJZnskNLGoB57YHFkO">