Skip to content

Instantly share code, notes, and snippets.

@PeterDKC
Last active March 14, 2022 23:35
Show Gist options
  • Save PeterDKC/81469cd01af73531ca3bb271652ff189 to your computer and use it in GitHub Desktop.
Save PeterDKC/81469cd01af73531ca3bb271652ff189 to your computer and use it in GitHub Desktop.
<?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