update
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait HasUuid
|
||||
{
|
||||
protected static function bootHasUuid(): void
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
foreach ($model->getUuidColumns() as $column) {
|
||||
if (empty($model->{$column})) {
|
||||
$model->{$column} = (string) Str::uuid();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function getUuidColumns(): array
|
||||
{
|
||||
return property_exists($this, 'uuidColumns')
|
||||
? $this->uuidColumns
|
||||
: ['uuid'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user