Traits work somehow like inheritance, if the same function is defined inside a trait and a class (in this case your model), the trait method gets overwritten by the class method.
Hi @Augustus , call bootRecordsActivity() inside boot()
protected static function boot()
{
parent::boot();
// ... Do something ...
// Call self::bootRecordsActivity()
self::bootRecordsActivity();
}
Don't forget to remove the call to parent::boot() in bootRecordsActivity(), since you already called it in boot(). And check for the error stack trace in storage/logs/laravel.log
@moharrum Thanks for your reply! That's great, gives me new perspectives. Yeah, removing the parent::boot() seemed to fix it for me.
I guess the way you describe it, I should add the self::bootRecordsActivity(); below the models parent::boot() that I had already created? Or perhaps in the EventServiceProvider?
Right now, I have
use RecordsActivity
Above the protected static function boot() in the model calling the trait and it seems to fork fine for now, is there any difference using the way you described above?
@Augustus Don't call boot() anywhere in your trait. Don't call bootRecordsActivity inside the boot method either.
Laravel designed it specifically because of issues like this. You'll see this line of code in your model's boot method:
protected static function boot()
{
static::bootTraits();
}
It already takes care of booting your traits, and you shouldn't try to override this in your trait or whatever. Otherwise, you can't have a boot method inside your own models.