Friday, March 17, 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();

Can I do it without using raw query or in other better way?



via user3529607

Advertisement