DEV Community

Discussion on: Easily use UUIDs in Laravel

Collapse
 
risingad profile image
Rising • Edited

I am getting issue with sync() method.
I did somthing like:

$page->users()->sync([auth()->id() => ['status_id' => 1]]);
Enter fullscreen mode Exit fullscreen mode

then i got this error:

SQLSTATE[HY000]: General error: 1364 Field 'page_id' doesn't have a default value 
Enter fullscreen mode Exit fullscreen mode
Collapse
 
risingad profile image
Rising
wilburpowery image
I am using laravel version 5.7
Collapse
 
bodrosh profile image
Bodrosh

I also encountered this problem, if you want to add a uuid to the table additionally when it already has a key, you can do this:

protected static function bootUsesUuid() {
static::creating(function ($model) {
if (! $model->uuid) {
$model->uuid = (string) Str::uuid();
}
});
}