I\'m trying to create tables that will have a primary key which is a UUID defined as binary(16)
instead of the default auto-incrementing id
field.<
So, I got the thing working like a charm (not tested unit testing):
class UuidModel extends Eloquent
is an older (Laravel 4) construct. We use class UuidModel extends Model
in Laravel 5The solution was to move the
UuidModel::creating(function ($model) {
echo "Creating Uuid Model...\n";
$model->{$model->getKeyName()} = (string)$model->generateNewId();
});
from AppServiceProvider::boot()
to EventServiceProvider::boot()
. No other changes were required. Everything worked as expected.
I still don't know why (2) works in EventServiceProvider
and not in AppServiceProvider
as explained in the official docs. But judging from the name, that's perhaps the way it was meant to be.