Ok, I'm making progress in some way.
$libraryList = Input::get('libraryList');
$fieldToExaminate = 'job_post_library_type.library_type_id';
$jobposts = JobPost::distinct()->where('status' ,1)->with(['libraryTypes' => function($query) use ($fieldToExaminate, $libraryList)
{
$query->whereIn('job_post_library_type.library_type_id', $libraryList);
}])->get();
But I found the resulting query wrong.
SQL: select `library_types`.*, `job_post_library_type`.`job_post_id` as `pivot_job_post_id`, `job_post_library_type`.`library_type_id` as `pivot_library_type_id`
from `library_types` inner join `job_post_library_type` on `library_types`.`id` = `job_post_library_type`.`library_type_id`
where `job_post_library_type`.`job_post_id` in (4, 6, 8, 10, 12) and `job_post_library_type`.`library_type_id` in (3))
I mean, I passing only the $libraryList var that are (3) in this case.
But the query is doing this job_post_library_type.
job_post_id` in (4, 6, 8, 10, 12) that I don't request.
Could you help me to solve this problem?
Ok, solved it. $jobposts = JobPost::whereHas('libraryTypes', function($q) { $q->whereIn('library_types.id', Input::get('libraryList')); })->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community