$users = User::whereHas('posts', function($q){
$q->where('created_at', '>=', '2015-01-01 00:00:00');
})->get();
// only users that have posts from 2015 on forward are returned
public function index()
{
$countryName = 'Brazil';
$users = User::with('country')
->whereHas('country', function (Builder $query) use($countryName) {
$query->where('name', 'like', "%{$countryName}%");
})
->get();
}
->whereHas('translation', function ($query) use ($name){
$query->where('name', 'like', $name);
}, '>=', 10)
User::select()->whereHas('student', $function($q) {
$q->where('name', $value)
->orWhere('age', $value2);
});
//https://laravel.com/docs/9.x/queries#conditional-clauses
$result = $query
->where('precedence', '=', $precedenceStatus)
->when($person, function ($query) use ($person) {
$query->whereHas('personnel', fn ($q) => $q->where('id', '=', $person));
})
->get();