633Innovations

Knowledgebase | Troubleshooting


Issue: Laravel 419 | Page Expired - Error Due to User Session Migration

Recently, we encountered a 419 | Page Expired error while working on the PrayerForced project. The root cause was related to the sessions' user ID field in the migration.

Since we're using UUIDs instead of the default auto-increment IDs, the sessions.user_id field needed to be updated accordingly. The default migration used foreignId, which caused issues because it was expecting an integer-based ID.

Original Code:

Schema::create('sessions', function (Blueprint $table) {
   $table->string('id')->primary();
   $table->foreignId('user_id')->nullable()->index();
   $table->string('ip_address', 45)->nullable();
   $table->text('user_agent')->nullable();
   $table->longText('payload');
   $table->integer('last_activity')->index();
});

Resolution:

I updated the migration to using foreignUuid for the user_id field, ensuring it aligns with our UUID implementation.

Updated Code:

Schema::create('sessions', function (Blueprint $table) {
   $table->string('id')->primary();
   $table->foreignUuid('user_id')->nullable()->index();
   $table->string('ip_address', 45)->nullable();
   $table->text('user_agent')->nullable();
   $table->longText('payload');
   $table->integer('last_activity')->index();
});

After making this change and refreshing the user migration (as the session migration is now included in the user migration in Laravel 11.x), the issue was resolved, and everything is functioning properly.