Last Updated: February 25, 2016
·
2.456K
· mabasic

Eloquent ORM with parentheses

If you are dealing with multiple AND and OR statements in your queries You will want to use parentheses to logically separate your query.

In Laravel 4 there is a easy way to do so:

$realestates = $realestates
    ->where( function ( $query )
{
    $query->whereBetween('price', array(Input::get('min_price'), Input::get('max_price')))
        ->orwhereBetween('price_per_day', array(Input::get('min_price'), Input::get('max_price')));
});