Method Illuminate\Database\Eloquent\Collection::lists does not exist

Updated at 24-Aug-2021, By samar

Method IlluminateDatabaseEloquentCollection::lists does not exist

In this session, we’ll try our hand at solving the "Method IlluminateDatabaseEloquentCollection::lists does not exist" puzzle by using the computer language.

Error Method Illuminate\Database\Eloquent\Collection::lists do not exist occurs when you call lists method on eloquent collection in Laravel version > 5.2. The lists() method has been deprecated from laravel version > 5.2. You can use the pluck method instead of the lists to get the same output.
  • Get array of ids from users table using pluck() method

    $userArrayIDs = User::get()->pluck('id');
    dd($userArrayIDs);
    
    Output :

    Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => 4 [1] => 41 [2] => 75 [3] => 77 [4] => 78 [5] => 79
    [6] => 80 [7] => 81 [8] => 82 [9] => 83 [10] => 84 ) )


    You can get all the ids of the user's table in an array form using the pluck() method in laravel.

Back to code snippet queries related laravel