Laravel Call undefined method lists Illuminate\Database\Query\Builder::lists()

Today, I am going to tell you about the "Laravel Call undefined method lists Illuminate\Database\Query\Builder::lists()" error and going to share solutions with you.

When I am working with Laravel many times I used the eloquent "lists" method for getting the lists of the names like the country name with the ID as the key like.

$country = Country::lists("name","id");
dd($country);

When I am trying the use the lists method on the laravel 5.3 I am getting the error  "Laravel Call undefined method Illuminate\Database\Query\Builder::lists()" like

BadMethodCallException in Builder.php line 2440: Call to undefined method 
Illuminate\Database\Query\Builder::lists()

Laravel Call undefined method lists

When I search for this error I found that the "lists" method is removed from the Laravel 5.3. Now, we get the same lists data using pluck method form the Laravel 5.3 like

$country = Country::pluck("name","id")->all();
dd($country);

Finally, We are getting the solution use pluck method instead of the lists. Still, if you face any issue write the comment below.

Tags:

Related Posts: