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.
// 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.