for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Thinkstudeo\Rakshak\Traits;
use Illuminate\Support\Str;
trait UuidAsPrimaryKey
{
/**
* Generate a uuid and insert it as primary key for the model being created.
* Set the $incrementing to false to use the uuid primary key.
*
* @return void
*/
public static function bootUuidAsPrimaryKey(): void
static::creating(function ($model) {
$model->{$model->getKeyName()} = Str::orderedUuid()->toString();
});
}