Skip to content

Commit 84b0d40

Browse files
authored
Generate ID using model event rather than passing null (#5)
1 parent 327df7b commit 84b0d40

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/Entries/Entry.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public function toModel()
3333
}
3434

3535
return $class::findOrNew($this->id())->fill([
36-
'id' => $this->id() ?? $class::generateId(),
3736
'origin_id' => $this->originId(),
3837
'site' => $this->locale(),
3938
'slug' => $this->slug(),

src/Entries/EntryModel.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,4 @@ public function getAttribute($key)
2626
{
2727
return Arr::get($this->getAttributeValue('data'), $key, parent::getAttribute($key));
2828
}
29-
30-
public static function generateId()
31-
{
32-
return null;
33-
}
3429
}

src/Entries/UuidEntryModel.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ class UuidEntryModel extends EntryModel
99
public $incrementing = false;
1010
protected $keyType = 'string';
1111

12-
public static function generateId()
12+
protected static function boot()
1313
{
14-
return (string) Str::uuid();
14+
parent::boot();
15+
16+
static::creating(function ($entry) {
17+
$entry->{$entry->getKeyName()} = (string) Str::uuid();
18+
});
1519
}
1620
}

0 commit comments

Comments
 (0)