Laravel 8 Wherein Eloquent Query Example

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Today now in this example,I will show you how to use wherein query in laravel 8 application. We can simply use to wherein query in our controller.

For example,we table with 5 record in 3 record get that define to wherein query in contoller.

So Let me tell you that these are the part of the query builder. Now we also know this by the name of eloquent query builder. So Wherein the query is used and how Ican use it, So here I will try to understand it by example.

Example 1 :

/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
    $users = User::wherein('id',[1,2,3])->get();

    dd($users);
}

Example 2 :

/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
    $users = DB::table('users')
                ->whereIn('id', [1, 2, 3])
                ->get();

    dd($users);
}

Example 3 :

/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
    $myArray = ["rakesh","ravi","mahesh"];

    $users = User::wherein('name',$myArray)->get();

    dd($users);
}

Read Also : Laravel 8 Eloquent Global Scope Tutorial Example

I hope it will help you. Also you can follow us on Facebook

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →