Multilevel relationship whereHas on eloquent Model in Laravel
Multilevel relationship whereHas on eloquent Model in Laravel I'd like to find Project::with('tasks.tags')->get(); Project::with('tasks.tags')->get(); where only projects with a particular id of tag return in the result set. For ex. I'd like to find a project with tasks and tasks with tags with only id of 1. In other words, filter the tasks return inside of the Project - Task relationship. I have tried various ways but have failed so far. I have tried: $project = Project::with('tasks.tags')->whereHas('tasks', function($query){ $query->whereHas('tags', function($query) { $query->where('id', 1); }); })->get(); And: $project = Project::with('tasks.tags')->whereHas('tasks', function($query){ $query->whereHas('tags', function($query) { $query->where('tag_id', 1); }); })->get(); This is how the re...
