Call to a member function pluck() on array

Created 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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.