Laravel Eloquent Multiple Where

hello developers, in this post, we will learn how to use “Laravel Eloquent Multiple Where”. as we knew that “where” is uses to make conditions in the query.

Generally, we use a single “where Eloquent”, But sometimes we need multiple “where” conditions for a query.

So here I will show how to use multiple where Eloquent in Laravel.

 public function index()
    {
        $product = Product::all();
        return view('welcome',compact('product'));
    }

Result

Example 1

WNow we want that product whose price is more than 500 and stock is more than 0. So Query will be

   public function index()
    {
        $product = Product::where('purchase_price','>','500')
                          ->where('current_stock','>','0')
                          ->get();
        return view('welcome',compact('product'));
    }

Result

Result

Example 2

We can write this multiple where Eloquent query with another method. to get same result.

    public function index()
    {
        $product = Product::where([['purchase_price','>','500'], ['current_stock','>','0']])
                          ->get();
        return view('welcome',compact('product'));
    }

Result

we got same result

I hope you understand how “Eloquent Multiple Where” works.