I am encountering the following error in my new installation of Laravel 11 and Vue.js when I try to submit a form, in this case, the Register form.
419 | PAGE EXPIRED
I have checked this question and yes, I do have @csrf
in my register form and
<meta name="csrf-token" content="{{ csrf_token() }}">
Steps to reproduce
composer create-project laravel/laravel test
cd test/
laravel/ui
packagecomposer require laravel/ui
php artisan ui vue --auth
It gave me a warning:
The [Controller.php] file already exists. Do you want to replace it? (yes/no) [yes]
I typed yes
then [Enter]
.
npm
packages and initialized vite
npm install && npm run dev
php artisan serve
Edit
There are additional steps that were done on the same repo
. We work with mongodb
hence we added the MongoDB configurations as well.
laravel/mongodb
packagecomposer require mongodb/laravel-mongodb
config/database.php
as below:'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE', 'assets'),
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),
'options' => [
'database' => env('DB_AUTHENTICATION_DATABASE', 'admin'),
],
],
.env
file as shown below:DB_CONNECTION=mongodb
DB_HOST=127.0.0.1
DB_PORT=27017
DB_DATABASE=testdb
DB_USERNAME=
DB_PASSWORD=
I am hoping there's someone with a solution.
NB I tried to install Laravel 10 and do the same processes and it works perfectly. What has changed in Laravel 11? Any help is appreciated.
Edit
Below is the contents of my bootstrap/app.php
.
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
and register.blade.php
<form method="POST" action="{{ route('register') }}">
@csrf
<div class="row mb-3">
// Rest of code
It seems like you're using the database
driver as your session driver. This is the default since Laravel 11.
I'm sure that this problem has something to do with MongoDB, but I would suggest you to use the file
session driver, you can do this by setting the SESSION_DRIVER
variable inside your .env
file to file
:
SESSION_DRIVER=file
Eitherway, in your case I don't see why you would need to use a database to store your sessions. Using filesystem is much faster and has way smaller overhead.