Tharindu Sameera
Tharindu Sameera

Reputation: 13

laravel withCount with count() not working

I want to get jobs count from the jobs table which are having at least one application. I try with this,

$jobs_count = Job::withCount('allApplications')->having('all_applications_count', '>', 0)->count();

but Unknown column 'allApplications_count' error. how to fix that? but,

$jobs_count = Job::withCount('allApplications')->having('all_applications_count', '>', 0)->get();

this is working.

Upvotes: 1

Views: 262

Answers (1)

OMR
OMR

Reputation: 12188

you can use has:

$jobsWithCommentsCount= Job::has('comments')->count();

Upvotes: 1

Related Questions