Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Eloquent uuid as primary key
<?php
public static function boot()
{
parent::boot();
$callback = function (Model $model) {
$model->setKeyType('string');
$model->setIncrementing(false);
if (! $model->getKey()) {
$model->{$model->getKeyName()} = \Str::uuid();
}
};
static::creating($callback);
static::retrieved($callback);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.