Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ogunlana Michael's avatar

Laravel Relationship?

I have an application, i have three tables, 1 - Course Module 2- Videos 3- Comments

I have this in the Course Module Model public function Comments() { return $this->hasManyThrough( Comment::class, VimeoVideo::class, 'module_video_categories_id', 'video_id', 'id', 'vimeo_id' ) } If I try this, the comment shows in every video in that module, and what i want is , it should only show in the video that the user makes a comment.

More so, on the comment table, the student id is there how do i fetch the student full details , since it is the only id.

In my controller, i have this

$data['modules'] = ModuleVideoCategory::where('series_id', $slug) ->where('series_id', Auth::guard('student')->user()->series_id) ->with('onlineVimeo') ->with('Comments') ->get();

0 likes
2 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Add them to the videos instead. Here they are nested under the video instead

$data['modules'] = ModuleVideoCategory::where('series_id', $slug) ->where('series_id', Auth::guard('student')->user()->series_id) ->with('onlineVimeo.comments')->get(); 

Please or to participate in this conversation.