for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Fyggi\SimpleUuid;
use Illuminate\Database\Eloquent\Builder;
use Ramsey\Uuid\Uuid;
trait HasUuid
{
public static function bootHasUuid(): void
static::creating(function ($model) {
if ($model->uuid === null) {
$model->uuid = Uuid::uuid4();
}
});
public function scopeWhereUuid(Builder $builder, string $uuid): Builder
return $builder->where('uuid', $uuid);
public function getRouteKeyName(): string
return 'uuid';
public function getRouteKey(): string
return $this->uuid;
uuid
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
public function getUuid(): string
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: