This commit is contained in:
Pusdatin BPKD Jkt
2022-07-11 16:26:39 +07:00
parent b2c962f2b5
commit a4de789b93
22 changed files with 731 additions and 236 deletions
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Traits;
use Illuminate\Support\Str;
trait Uuids
{
/**
* Boot function from Laravel.
*/
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
if (empty($model->{$model->getKeyName()})) {
$model->{$model->getKeyName()} = Str::uuid()->toString();
}
});
}
/**
* Get the value indicating whether the IDs are incrementing.
*
* @return bool
*/
public function getIncrementing()
{
return false;
}
/**
* Get the auto-incrementing key type.
*
* @return string
*/
public function getKeyType()
{
return 'string';
}
}