Home Laravel Laravel 8 Wherein Eloquent Query Example

Laravel 8 Wherein Eloquent Query Example

by Shahriar Sagor

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

close

You may also like