and or and 2b brackets with eloquent

Solutions on MaxInterview for and or and 2b brackets with eloquent by the best coders in the world

showing results for - "and or and 2b brackets with eloquent"
Camilla
27 Aug 2020
1
2//mysql query be like this
3// ... WHERE (gender = 'Male' and age >= 18) or (gender = 'Female' and age >= 65)
4
5//Eloquent query is
6// ...
7$q->where(function ($query) {
8    $query->where('gender', 'Male')
9        ->where('age', '>=', 18);
10})->orWhere(function($query) {
11    $query->where('gender', 'Female')
12        ->where('age', '>=', 65);	
13})
14//@sujay