php - In Laravel Eloquent, select "whereIn" from parent table -


in laravel project (with mysql database), have few models: time entries, tasks, , projects.

time entries belong tasks

tasks belong projects

so each table contains column corresponding id of parent.

i have array of project ids, , trying select time entries which, through tasks, belong projects.

in other words, i'd able this:

$timeentries = timeentry::wherein('project_id',$projectids)->get(); 

but obviously, column not found error, because i've got in time entries table task_id rather project_id.

is there way select desired time entries (based on project ids have) in single eloquent query? appreciated.

add following method in project model

public function timeentries() {     return $this->hasmanythrough('app\timeentry' , 'app\task'); } 

now can time entries of project below

$project = project::find(id); $project->timeentries()->get(); 

Comments