How to solve Call to undefined method Illuminate\Database\Query\Builder::lists() in Laravel ?

Today now in this post i will show here How to solve Call to undefined method Illuminate\Database\Query\Builder::lists() in Laravel ? Here i want to talk you about an error “Call to undefined method Illuminate\Database\Query\Builder::lists()” and also here we know how to solve this error in Laravel application.

sometimes when we are working on our Laravel application, on that time we need to get the lists of email and id of users table for the select drop-down. But when we are use lists() with the DB table then we will found error as like this “Call to undefined method Illuminate\Database\Query\Builder::lists()”.

So Error was as like bellow preview:

BadMethodCallException in Builder.php line 2440: Call to undefined method 

Illuminate\Database\Query\Builder::lists()

Here is a solution of this method by using pluck(). So we can solve our problem like as bellow:

Not Working:

$users = \DB::table("users")->lists("email","id");
dd($users);

Working Example:

$users = \DB::table("users")->pluck("email","id")->all();
dd($users);

Read Also: How to implement infinite ajax scroll pagination in Laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook

Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.