DEV Community

Websolutionstuff
Websolutionstuff

Posted on • Originally published at websolutionstuff.com

Laravel whereIn and whereNotIn Query Example

In this example we will see laravel whereIn and whereNotIn query example. laravel query builder provides many diffrent types of query to filter data from datatable.

The whereIn method verifies that a given column's value is contained within the given array and the whereNotIn method verifies that the given column's value is not contained in the given array.

So here we will see laravel whereIn and laravel whereNotIn query with example.

Syntax :

whereIn(Coulumn_name, Array)

Example :

SQL Query

SELECT * FROM students WHERE roll_no IN (1,2,3) 
Enter fullscreen mode Exit fullscreen mode

Laravel whereIn Query

public function index()
{
    $students = Student::select("*")
                ->whereIn('roll_no', [1,2,3])
                ->get();

    dd($students);                    
}
Enter fullscreen mode Exit fullscreen mode

Laravel whereNotIn Query

public function index()
{
    $roll_no = '1,2,3';
    $array1 = explode(',', $roll_no);

    $student = Student::select("*")
                    ->whereNotIn('roll_no', $array1)
                    ->get();

    dd($student);                    
}
Enter fullscreen mode Exit fullscreen mode

Read Also : How To Create Custom Middleware In Laravel


Read Also : How To Get Selected Checkbox List Value In JQuery

Thanks for the reading...!!
Don't forgot to like, share and comments.

Discussion (0)