Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given

Sometimes we get error Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given because we passed value to the query which is not in array format.

Answers 2
  • WhereNotIn() query example in laravel

    --PATH routes\web.php
    Route::get('/whereNotIn-with-array', function(){
        $usersIdArray = array('1', '2', '3');
        $users = App\Models\User::whereNotIn('id', $usersIdArray)->get();
        return $users;
    });
    
    0

    You can check the variable before passing to the whereNotIn(). If the type of $array variable is not an array then you can convert it to an array and also pass an empty array if you don’t want to pass any data to it.

    It will return all the records (user) from users table except the user which has id 1, 2, 3.

  • Pass null argument to WhereNotIn() query

    --PATH routes\web.php
    //Code with error - to see the error message
    Route::get('/whereNotIn-with-null', function(){
        $usersId = null;
        $users = App\Models\User::whereNotIn('id', $usersId)->get();
    });
    
    0

    It will return Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given.

  • Back to code snippet queries related laravel