In this tutorial you will learn about the How to Use WhereIn Query in Laravel and its application with practical example.
In this Laravel 8 WhereIn Database Query Examples tutorial I will show you how to use WhereIn query in laravel. In this tutorial you will learn to use WhereIn with laravel query builder and eloquent model. In this article I will share various example to use WhereIn query in laravel. In this tutorial you will learn about syntax and use of laravel WhereIn method.
Table Of Contents−
Laravel WhereIn Database Query
Laravel WhereIn method will return the records with having column values in provided list. Here is the general syntax of the laravel WhereIn method:
Syntax:-
1 |
whereIn(CoulumnName, Array); |
Laravel WhereIn Query with Laravel Query Builder
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php namespace App\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\DB; class UserController extends Controller { public function index() { $users = DB::table('products') -> whereIn('name', ['1', '3', '5']) ->get(); return view('home', ['products' => $products]); } } |
Laravel WhereIn Query with Laravel Model
In this example we will use laravel WhereIn method with laravel model.
Example:-