agilasadi
234
10
Laravel

It seems like laravel boot Trait doesn't work

Posted 1 month ago by agilasadi

Recently I'm having problems with using traits, I created some before and it seemed to work, but now I created another one to take action on a creating event, here it is


trait Contributes
{

public static function bootContributes()
{
    static::creating(function ($model) {
        if (!$model->getKey())
        {
            Contribution::create([
                'contributing_id' => $model->id,
                'contributing_type' => $model->class_table,
            ]);
        }
    });
}

}

and I included it in multiple models like use Contributes; I think there is something I don't know about it.

Please sign in or create an account to participate in this conversation.