Multiple Laravel bootable traits not working

Viewed 152

Using multiple boot traits with the same event will fire just the first one and ignore the rest bootable traits.

class Tag extends Model
{
    use HasKey; // this will work (but if i put it bellow it will not work)
    use HasSlug; // this's not (but if i put it above it will work)
}
trait HasKey
{
    public static function bootHasKey()
    {
        static::creating(
            fn (Model $model) => $model->key = 'value'
        );
    }
trait HasSlug
{
    public static function bootHasSlug()
    {
        static::creating(
            fn (Model $model) => $model->slug = 'value'
        );
    }
}
1 Answers
Related