Thursday, March 16, 2017

Eloquent way to filter by average of 2 columns

I have a JobPosts table and I want to select all the records with average salary is greater then given value. I can do it by using raw query but I feel that I am missing something. My code:

$salary = 100000;
$query = JobPost::whereRaw('("salary_min" + "salary_max")/2 >= ' . $salary)->getQuery();



via user3529607

Advertisement