Trying To Define a Relationship With Two Possible Foreign Keys

Viewed 70

I am using the Spatie Activitylog extension in Laravel 8 in a project to track funnily enough activities within the site. Within the activity model there are two polymorphic relationships defined as causer and subject. In my user model I am trying to create a relationship which will return all related activity models where the user is in either the causer or subject polymorphic fields.

The two relationships I have in there so far are...

public function activitiesOn(): MorphMany {
      return $this->morphMany(App\Model\Activity, 'subject');
  }


public function activitiesBy(): MorphMany {
    return $this->morphMany(App\Model\Activity, 'causer');
}

But I am struggling to figure out a way to get activities returned by both those relationships to show up as a single entry in the returned model under activities.

0 Answers
Related