Laravel whereIn and whereNotIn Query Example

In this tutorial, we will see the laravel whereIn and whereNotIn query examples. Laravel query builder provides many different types of queries to filter data from databases.

The whereIn method verifies that a given column’s value is contained within …


This content originally appeared on DEV Community and was authored by Techsolutionstuff

In this tutorial, we will see the laravel whereIn and whereNotIn query examples. Laravel query builder provides many different types of queries to filter data from databases.

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. Also, you can make a laravel wherein subquery and laravel where not in the subquery.

So, here we will see the laravel whereIn and laravel whereNotIn query with example. Also, you use whereIn and WhereNotIn in laravel 6, Laravel 7 and Laravel 8.

Syntax :

whereIn(Coulumn_name, Array)

SQL Query :

SELECT * FROM students WHERE roll_no IN (1,2,3) 

Read Also : Laravel whereBetween Query Example

Laravel whereIn Query :

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

    dd($students);                    
}

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);                    
}

You might also like :


This content originally appeared on DEV Community and was authored by Techsolutionstuff


Print Share Comment Cite Upload Translate Updates
APA

Techsolutionstuff | Sciencx (2022-04-11T03:19:45+00:00) Laravel whereIn and whereNotIn Query Example. Retrieved from https://www.scien.cx/2022/04/11/laravel-wherein-and-wherenotin-query-example/

MLA
" » Laravel whereIn and whereNotIn Query Example." Techsolutionstuff | Sciencx - Monday April 11, 2022, https://www.scien.cx/2022/04/11/laravel-wherein-and-wherenotin-query-example/
HARVARD
Techsolutionstuff | Sciencx Monday April 11, 2022 » Laravel whereIn and whereNotIn Query Example., viewed ,<https://www.scien.cx/2022/04/11/laravel-wherein-and-wherenotin-query-example/>
VANCOUVER
Techsolutionstuff | Sciencx - » Laravel whereIn and whereNotIn Query Example. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/11/laravel-wherein-and-wherenotin-query-example/
CHICAGO
" » Laravel whereIn and whereNotIn Query Example." Techsolutionstuff | Sciencx - Accessed . https://www.scien.cx/2022/04/11/laravel-wherein-and-wherenotin-query-example/
IEEE
" » Laravel whereIn and whereNotIn Query Example." Techsolutionstuff | Sciencx [Online]. Available: https://www.scien.cx/2022/04/11/laravel-wherein-and-wherenotin-query-example/. [Accessed: ]
rf:citation
» Laravel whereIn and whereNotIn Query Example | Techsolutionstuff | Sciencx | https://www.scien.cx/2022/04/11/laravel-wherein-and-wherenotin-query-example/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.