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.

Answers 1
  • 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');
    
    0
  • Back to code snippet queries related laravel