Commit 83b4f371 by f3brysan

#7: Auto Generate UUID

parent a5d6c5c4
<?php
namespace App\Traits;
use Illuminate\Support\Str;
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
trait Uuid
{
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
try {
$model->id = (string) Str::uuid(); // generate uuid
// Change id with your primary key
} catch (UnsatisfiedDependencyException $e) {
abort(500, $e->getMessage());
}
});
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment