Call to a member function pluck() on array

Updated at 26-Aug-2021, By samar

Call to a member function pluck() on array

In this session, we will try our hand at solving the "Call to a member function pluck() on array".

Error Call to a member function pluck() on array occurs when we call pluck method on array instead of object.
  • Call pluck method on object instead of array

    //Code with error
    $userIDs = App\Models\User::get()->toArray()->pluck('id');
    
    //Code with solution
    $userIDs = App\Models\User::get()->pluck('id');
    

Back to code snippet queries related laravel