Laravel where In Eloquent Query Example - Yudhy Network

Share on:

Yudhy Network - Laravel wherein query example tutorial. Here you will learn how to use laravel wherein() eloquent method with laravel query builder and model.

Laravel provides various eloquent methods. In this laravel where in query with column example tutorial, you will how to use laravel eloquent whereIn() method to building a query with laravel model and query builder.

This tutorial provides you simple examples of laravel wherein method on query builder and model with columns. And as well as how to use laravel eloquent wherein with arrays.

The following syntax represents the whereIn eloquent method in laravel:

whereIn(Coulumn_name, Array);

Here,

  • Column_name:- Your database table column name.
  • Array: – array with comma-separated values.

Let’s take look at some example of whereIn() eloquent method in laravel:

Example 1: wherein Query Using Simple SQL Query:

SELECT *  FROM users  WHERE id IN (10, 15, 18) 

In this query, the data will be get from the DB table. Whose ids will be 10, 15, 18.

Example 2: Eloquent Wherein Query Using Query Builder

public function index()
{
    $data = DB::table('users')
                ->whereIn('id', [10, 15, 18])
                ->get();
  
    dd($data);                    
}
Recommended:- Laravel Where Multiple Columns Example

Example 3: Eloquent Wherein Query Using Laravel Model

public function index()
{
    $data= User::whereIn('id', [10, 15, 18])->get();
  
    dd($data);                    
}

So far you have seen in the given example. Have used ids for getting data into db table. But now for example 4, we will fetch the data by using the DB table column name.

Recommended:- Laravel whereIn and whereNotIn Subquery Example

Example 4: Eloquent Wherein Query Using Laravel Model With Different Column Name

public function index()
{
    $data= User::whereIn('name', ['john','dam','smith'])->get();
  
    dd($data);                    
}

Conclusion

Laravel wherein query example tutorial, you have learned how to use laravel wherein() method with eloquent query builder and model.

Recommended Laravel Posts

Recommended:- Laravel Eloquent whereRaw Query Example
Recommended:- Laravel where Like Query Example
Recommended:- Laravel where Between Dates Eloquent Query
Recommended:- Laravel where Not In Eloquent Query Example
Recommended:- Laravel WhereHas Eloquent Example
Recommended:- Laravel where Not Between Query Example
Recommended:- Laravel whereExists and where Not Exists Query Example
Recommended:- Laravel Pluck Method Example
Recommended:- Laravel Where Null and Where Not Null Query
Recommended:- Laravel Group by Example
Recommended:- Laravel Order by Example
Recommended:- Laravel InsertOrIgnore Example

Please ask in the comments!

Suport : Cotekno.Com

comments powered by Disqus