I am building a model and using chelout/laravel-relationship-events to capture events.
I have a model that looks like this:
class Taxonomyterm extends Model
{
use HasMorphToManyEvents, HasMorphedByManyEvents {
HasMorphedByManyEvents::newMorphToMany insteadof HasMorphToManyEvents;
}
...
public function images()
{
return $this->morphToMany(Image::class, 'imageable')->withTimestamps();
}
public function items()
{
return $this->morphedByMany(Item::class, 'taxonomytermable')->orderBy('taxonomytermables.id')->withPivot('id')->withTimestamps();
}
...
protected static function boot()
{
parent::boot();
static::morphToManyAttached(function ($relation, $parent, $ids, $attributes) {
if( $relation == 'images') {
dd('Attached MorphToMany');
}
}
static::morphedByManyAttached(function ($relation, $parent, $ids, $attributes) {
if( $relation == 'items') {
dd('Attached MorphedByMany');
}
}
}
I was pointed to PHP docs by the maintainer of the package, and can't seem to find the right way to make this work.
I also assume that newMorphToMany is the method that conflicts between the two traits.
I am essentially lost on what to do from here to get both HasMorphToManyEvents and HasMorphedByManyEvents working on the same model. Package this is from