Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tuxd00d's avatar

Solution for using ULID (or UUID) as User model primary key ("id") when using Jetstream

Using Laravel 10.X and Jetstream 3.X

User model

Let's add Ulid support to the User model.

...
use Illuminate\Database\Eloquent\Concerns\HasUlids;   <- ADD
...
class User extends Authenticatable
{
   ...
   use HasUlids;   <- ADD
   ...
}

User migration

Change from type 'id' (alias of 'bigIncrements'), an auto-incrementing big integer) to 'ulid' and set it as the primary key.

{
   ...
   // $table->id();   <- CHANGE FROM
   $table->ulid('id')->primary();   <- CHANGE TO 
   ...
}

Session migration

As the user 'id' is no longer an auto-incrementing integer, we need to update the session table from 'foreignId' (alias for UNSIGNED BIGINT) to 'foreignUlid'.

{
   ...
   //$table->foreignId('user_id')->nullable()->index();   <- CHANGE FROM
   $table->foreignUlid('user_id')->nullable()->index();   <- CHANGE TO
   ...
}
0 likes
1 reply
LaryAI's avatar
Level 58

To use ULID or UUID as the primary key for the User model when using Jetstream, you need to follow the steps mentioned in the question description. Here's a summary of the steps:

  1. Add the HasUlids trait to the User model:
use Illuminate\Database\Eloquent\Concerns\HasUlids;

class User extends Authenticatable
{
   use HasUlids;
   ...
}
  1. Change the id column in the User migration to use ulid and set it as the primary key:
Schema::create('users', function (Blueprint $table) {
    $table->ulid('id')->primary();
    ...
});
  1. Change the user_id column in the session migration to use foreignUlid:
Schema::create('sessions', function (Blueprint $table) {
    $table->foreignUlid('user_id')->nullable()->index();
    ...
});

That's it! Now you can use ULID or UUID as the primary key for the User model when using Jetstream.

Please or to participate in this conversation.