Laravel Eloquent Where Query Tutorial With Examples

laravel eloquent where eloquent model that allows the interaction with a database. here you can learn to Laravel Eloquent Tips and Tricks.

laravel eloquent where – Tips and Tricks

Eloquent: find() and multiple where() OR clause. usage laravel Example. It is an MVC based PHP framework.

Syntax:

where('COLUMN_NAME', 'OPERATOR', 'VALUE')

SQL Query

select * from `products` where `is_active` = 1

Example 1:

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use App\Product;
  
class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $products = Product::select("*")
                        ->where("is_active", "=", 1)
                        ->get();
  
        dd($products);
    }
}

Don’t miss : Laravel Eloquent Query Where Exists MySQL

Example 2: without Pass Operator in Laravel

<?php
  
namespace App\Http\Controllers;
 
use Illuminate\Http\Request;
use App\Product;
  
class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $products = Product::select("*")
                        ->where("is_active", 1)
                        ->get();
  
        dd($products);
    }
}

Example 3: Multiple Where Condition in Laravel 8

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use App\Product;
  
class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $products = Product::select("*")
                        ->where([
                            ["status", "=", 1],
                            ["email", "=", "[email protected]"]
                        ])
                        ->get();
  
        dd($products);
    }
}

There are the Following The simple About AND-OR-AND + brackets with Laravel Eloquent Multiple WHERE Clauses and source code.

Example 4:

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use App\Product;
  
class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $products = Product::select("*")
                        ->where("likes", ">", 145)
                        ->get();
  
        $products2 = Product::select("*")
                        ->where("likes", "<=", 5265)
                        ->get();
  
        $products3 = Product::select("*")
                        ->where("name", "like", "ipho%")
                        ->get();
  
    }
}

I hope you get an idea about laravel eloquent where.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.