Before reading below make sure you have @csrf
or {{ csrf_field() }}
in your form
like
<form method="post">
@csrf <!-- {{ csrf_field() }} -->
... rest of form ...
</form>
The Session Expired or 419 Page Expired error message in Laravel comes up because somewhere your csrf token verification fails which means the AppHttpMiddlewareVerifyCsrfToken::class
middleware is already turned on. In the form the @csrf
blade directive is already added, which should be fine as well.
Then the other area to check is the session. The csrf
token verification is directly involved with your session, So you might want to check whether your session driver is working or not, such as an incorrectly configured Redis might cause an issue.
Maybe you can try switching your session driver/software from your .env
file, the supported drivers are given below
Supported Session drivers in Laravel 5, Laravel 6 and Laravel 7 (Doc Link)
file
- sessions are stored in storage/framework/sessions.
cookie
- sessions are stored in secure, encrypted cookies.
database
- sessions are stored in a relational database.
memcached
/ redis
- sessions are stored in one of these fast, cache based stores.
array
- sessions are stored in a PHP array and will not be persisted.
If your form works after switching the session driver, then something wrong is with that particular driver, try to fix the error from there.
Possible error-prone scenarios
Probably file-based sessions might not work because of the permission issues with the /storage
directory (a quick googling will fetch you the solution), also remember putting 777 for the directory is never the solution.
In the case of the database driver, your DB connection might be wrong, or the sessions
table might not exist or wrongly configured (the wrong configuration part was confirmed to be an issue as per the comment by @Junaid Qadir).
redis/memcached
configuration is wrong or is being manipulated by some other piece of code in the system at the same time.
It might be a good idea to execute php artisan key:generate
and generate a new app key which will, in turn, flush the session data.
Clear Browser Cache HARD, I found Chrome and Firefox being a culprit more than I can remember.
Read more about why application keys are important
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…