0

I have a table to persist all reactions available on the app (reactions) and N tables to be related to this in many-to-many relation with a pivot table.

Ex: ERM

// Post Model
public function reactions()
{
    return $this->belongsToMany(Reaction::class, 'reactions_posts')
        ->with('reactors')->groupBy('reaction_id');
}

// Reactions Model
public function post()
{
    return $this->hasMany(Post::class, 'reactions_posts');
}

public function reactors(){
    return $this->hasMany(User::class, 'reactions_posts');
}

Once N models could be related to Reactions model using a pivot, I am looking for a better way to relate Post x Reaction, Event x Reaction and all required models who will be related using this same principle, since this way would create some dependency of Post, Event and all on Reaction model.

fiskolin
  • 1,421
  • 2
  • 17
  • 36
  • 1
    Have you considered using Polymorphic Relationships? https://laravel.com/docs/5.8/eloquent-relationships#polymorphic-relationships – dparoli Mar 02 '19 at 19:35
  • Yes, but seems that I need to add dependency on Reactions by related models as well, and I wan't some how remove this dependency. – fiskolin Mar 04 '19 at 17:30

0 Answers0