Laravel's new(ish) booted()
model method and PHP arrow functions can (subjectively) really cleaned up these little model event listeners!
<?php
// ...
class Team extends Model
{
// Before
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->uuid = Str::uuid()->toString();
});
}
// After
protected static function booted()
{
static::creating(fn ($model) => $model->uuid = Str::uuid()->toString());
}
}