whereIn and wherenotIn in query in laravel 8

in this article, i will give whereIn and wherenotIn in query in laravel, and i will give step by step codes to you and get whereIn() method & wherenotIn() methos code with example.

Syntax : whereIn and wherenotIn in query in laravel

whereIn(Coloum_name, Array)

Step Example :

Sql Query:

SELECT * FROM users WHERE user_id IN (1,2,3) 

Laravel whereIn Query

public function first()
{
    $users = User::select("*")
                ->whereIn('user_id', [1,2,3])
                ->get();
  
    dd($students);                    
}

Laravel whereNotIn Query

public function first()
{
    $user_id = '1,2,3';
    $array1 = explode(',', $user_id);
    
    $users = User::select("*")
                    ->whereNotIn('user_id', $array1)
                    ->get();
  
    dd($student);                    
}

Read Also : How To Create Zip File And Download In Laravel 7/8?

Leave a Comment