Last active
March 14, 2022 23:35
-
-
Save PeterDKC/81469cd01af73531ca3bb271652ff189 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models; | |
use Illuminate\Support\Str; | |
use Illuminate\Database\Eloquent\Model; | |
use Illuminate\Database\Eloquent\Factories\HasFactory; | |
class Foo extends Model | |
{ | |
use HasFactory; | |
public $fillable = [ | |
'uuid' | |
]; | |
public static function boot() | |
{ | |
parent::boot(); | |
self::creating(function ($model) { | |
$model->uuid = Str::uuid()->toString(); | |
}); | |
} | |
public function getRouteKeyName() | |
{ | |
return 'uuid'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment