I recently created a project where I wanted my user's to be represented with a uuid.
UUID v7 allows for a balanced option between randomly generated, unpredictable user IDs, and sequential IDs.
The first few characters of a UUID v7 are based on the current timestamp, allowing for the IDs to be sorted.
This is ideal I thought...
First I modified my user table migration
Schema::create('users', function (Blueprint $table) {
$table->uuid('id')->primary();
...
}
This worked a treat, I was now able to set uuids as IDs.
But when I tried to log into Laravel Nova, I found I was not getting any error, but being redircted back from the dashboard.
After much investigation and finding no answers on a google search, I realised this was my issue.
If you want to use a uuid in your user model (or any model for that matter) you should add the following fields to your User model:
public $incrementing = false;
protected $keyType = 'string';
Further to this, if you are using Laravel Passport, you will want to override this function too:
public function findForPassport($username) {
return $this->where('id', $username)->first();
}