28 lines
522 B
PHP
28 lines
522 B
PHP
<?php
|
|
|
|
namespace App\Models\Concerns;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
trait UsesStringIds
|
|
{
|
|
protected static function bootUsesStringIds(): void
|
|
{
|
|
static::creating(function ($model): void {
|
|
if (! $model->getKey()) {
|
|
$model->setAttribute($model->getKeyName(), Str::lower(Str::random(25)));
|
|
}
|
|
});
|
|
}
|
|
|
|
public function getIncrementing(): bool
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function getKeyType(): string
|
|
{
|
|
return 'string';
|
|
}
|
|
}
|