DEV Community

loading...

Discussion on: 5 tips for supercharged Laravel Eloquent queries

Collapse
nicoaudy profile image
Nico Audy

You can do more tidying using when 🔥

return Property::when(request('rent')), function($query){
    $query->where('rent', '<=', request('rent'));
})->when(request('pets'), function($query){
    $query->where('pets_allowed', true));
});
Collapse
aschmelyun profile image
Andrew Schmelyun Author

Woah! I had no idea about this, thanks Nico!