In this tutorial you will learn about the Laravel Multiple Where Conditions Example and its application with practical example.
In this Laravel Multiple Where Conditions Example tutorial, I’ll show you how to use multiple where clause in laravel eloquent query.
Laravel Multiple Where Conditions Example
In laravel, when you fetch data from database tables you come to situation when you need to pass multiple conditions in laravel query. In laravel eloquent queries this can be done by providing multiple where clause in laravel eloquent query. In this tutorial, you will learn how to create and use multiple where clause query using laravel eloquent. Laravel eloquent model allows you to provide multiple where conditions to fetch required data. In this tutorial you will learn to use multiple where conditions with eloquent queries.
In this article we will share various examples of how to add multiple where clause with laravel search query with multiple conditions, update query with multiple conditions, delete query with multiple conditions, and relationship with multiple conditions in laravel.
Laravel multiple where clause
In this example we will be using Multiple where conditions in laravel query:
1 2 3 4 5 6 7 |
public function index() { $users = User::where([["status" => 1], ["is_banned" => 0]]) ->get(['name']); dd($users); } |
Laravel multiple where with Relationship
Open your model file and create scopes as following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public function scopeActive($query) { return $query->where('active', '=', 1); } public function scopeThat($query) { return $query->where('that', '=', 1); } |
Then call scops as following:
1 2 3 4 5 6 |
public function index() { //Then call the scopes as given below $users = User::active()->that()->get(); } |