I have three tables that are related through other tables :
Serie
public function episodes()
{
return $this->hasManyThrough(Episode::class, Season::class);
}
Episodes
public function chaines()
{
return $this->belongsToMany(Channel::class, 'programmation', 'episode_id', 'channel_id');
}
Channel
public function episodes()
{
return $this->belongsToMany(Episode::class, 'programmation', 'channel_id', 'episode_id');
}
I would like to have channels for one serie. I need to check for the programmation table. In my blade view, I have this :
@foreach($serie->episodes as $episode)
@foreach($episode->chaines as $chaine){{$chaine->name}}
@endforeach
@endforeach
But it gives me the channel of all the episodes (the same one essentially). How can I do to have just one channel if they're the same ? Sometimes, the episodes are on different channel so i need to check that too.