Eloquent Laravel Where Query Examples

In this tutorial will give you simple example of where query in laravel query.This tutorial will give you simple example of where query in laravel.where query use of laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10.

I will share simple examples of how to use sql where query in laravel.see below simple examples that will help you how to write database where condition.

Syntax:
where('COLUMN NAME', 'OPERATOR', 'VALUE')
SQL Query:
select * from 'users' where 'active'= 1;
Example: Eloquent where query
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserController extends Controller
{
    public function index()
    {
        $users = User::select("*")
            ->where("active","=", 1)
            ->get();
        dd($users);
    }
}
Example 2: Without pass operator
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserController extends Controller
{
    public function index()
    {
        $users = User::select("*")
            ->where("active", 1)
            ->get();
        dd($users);
    }
}
Example 3: Multiple where query
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserController extends Controller
{
    public function index()
    {
        $users = User::select("*")
            ->where(["active", "=", 1],
            ["email","=", "Your email"])
            ->get();
        dd($users);
    }
}

I hope this tutorial help you.

Leave a Reply

Your email address will not be published. Required fields are marked *