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

amjadkhan896's avatar

Eloquent Query Issue

Hi all, I have one query issue. I have small table. having four columns that are customer_id, job_id and timestamp. I already created one to one relationship. for both tables now the issue is I want to to show the total applicants applied for the same job. My Query at the moment is

CustomerJobApplication::with(['jobApplied' , 'customer')->where('customer_id',auth()->guard('customer')->id())->get(); My requirement is that i need the total applicants applied for each job also Thanks

0 likes
3 replies
burlresearch's avatar
Level 40

To get that count, I think what you really want is the Job->applicants:

\App\Job::find($jobId)->applicants->count()
1 like
amjadkhan896's avatar

@burlresearch thanks for the reply. But it seems that i will query again and will call the relationship. But is it possible to do all in one statement like CustomerJobApplication::with(['job' , 'customer')->where('customer_id',auth()->guard('customer')->id())->get(); can we modify the above one

Please or to participate in this conversation.