skip to Main Content

I am encountering the following error in my new installation of laravel 11 and vue 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

  1. I installed a fresh instance of laravel 11:
 composer create-project laravel/laravel test
 cd test/
  1. I added the laravel/ui package
 composer require laravel/ui
  1. I added the vue and auth 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]

  1. I installed the npm packages and initialized vite
 npm install && npm run dev
  1. Iniatilized the dev server and tried to register
 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.

  1. Installed the laravel/mongodb package
 composer require mongodb/laravel-mongodb
  1. Added the configurations in 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'),
          ],
      ],

  ...
  1. Updated .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

<?php

use IlluminateFoundationApplication;
use IlluminateFoundationConfigurationExceptions;
use IlluminateFoundationConfigurationMiddleware;

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

2

Answers


  1. Although the question doesn’t explicitly mention it, I believe you’ve switched the default database to MongoDB as well.

    Since this was set up this way after installation, it may be necessary to regenerate the table for the Session.

    In Laravel 11, this command would have been automatically executed by php artisan migrate, but it was performed before installing MongoDB. I assume that after migrating to the new database, you would need to rerun the migrate command separately. Otherwise, only the session table can be created manually.

    php artisan make:session-table
    

    More information

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search