Eloquent Query Using WHERE with OR AND OR? | Laravel Point

 

Eloquent Query Using WHERE with OR AND OR?

In Laravel Eloquent, you can use the where method to specify conditions for retrieving records from the database. To use where with OR and AND conditions, you can chain multiple where methods together. Here's an example:

$users = User::where('name', 'John')
        ->orWhere(function ($query) {
            $query->where('name', 'Jane')
                ->where('age', '>', 25);
             })
             ->orWhere('email', 'john@example.com')
             ->get();

 

This will retrieve all the User records with name equal to John, or name equal to Jane and age greater than 25, or email equal to john@example.com.

Previous Post Next Post

Contact Form