Support the ongoing development of Laravel.io →
Database Eloquent Forms
Last updated 2 years ago.
0

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?

0

Ok, solved it. $jobposts = JobPost::whereHas('libraryTypes', function($q) { $q->whereIn('library_types.id', Input::get('libraryList')); })->get();

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Cuboatgit cuboatgit Joined 12 Mar 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.