Laravel 7|8 Eloquent Multiple Where Clause Query Example

Last updated on by Digamber

Throughout this tutorial, you will learn how to write multiple where conditions with Laravel Query Builder. This is a simple yet powerful example of the Laravel eloquent Multiple Where clause.

By the end of this tutorial, you will be able to understand how to deal with Multiple Where Query in Laravel application.

In the below example, we will make sure to write the multiple where query using the laravel where() method.

Here you can have a quick look at the where() condition.

->where('column_name', 'operator', 'value')

We will write multiple where conditions with the query builder and eloquent model. I am going to share with you the following methods you decide which work best for you.

Multiple Where Condition with Query Builder

If you want to write multiple where clause, then you can go with the laravel query builder method.

<?php
namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class CountryController extends Controller
{

    public function index()
    {
        $words = DB::select('*')
        ->where('hey', '=', 1)
        ->where('hello', '=', 1)
        ->where('hey_there', '=', 1)
        ->where('hi_there', '=', 1)
        ->where('you_and_i', '=', 1)
        ->where('thunder_is_blunder', '=', 1)
        ->where('when_then', '=', 1)
        ->where('this_is_me', '=', 1)
        ->get();

        print_r($words);
    }

}

Laravel Multiple Where Clause with Eloquent Model

If you want to write multiple where query, then you can adopt the following eloquent model process.

<?php
namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Book;

class CountryController extends Controller
{

    public function index()
    {
        $book = Book::table('students')
        ->where('hey', '=', 1)
        ->where('hello', '=', 1)
        ->where('hey_there', '=', 1)
        ->where('hi_there', '=', 1)
        ->where('you_and_i', '=', 1)
        ->where('thunder_is_blunder', '=', 1)
        ->where('when_then', '=', 1)
        ->where('this_is_me', '=', 1)
        ->get();

        print_r($book);
    }

}