Laravel - Call to Undefined Method Illuminate\Database\Query\Builder::lists() Solved
Today i want to tell you about error "Call to undefined method Illuminate\Database\Query\Builder::lists()" and how to solve this error in Laravel 5.3.
When i was working on my Laravel 5.3 application, at that time i require to get lists of email and id of users table for select drop-down. But when i use lists() with DB table i found error "Call to undefined method Illuminate\Database\Query\Builder::lists()".
Error was like bellow preview:
BadMethodCallException in Builder.php line 2440: Call to undefined method
Illuminate\Database\Query\Builder::lists()
I did search a lot on docs and google, But finally i found i think Laravel 5.3 removed lists() on query builder.
But i found solution of this method using pluck(). So you can solve your solution 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);
Maybe it can help you.....
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Find Multiple Ids using Laravel Eloquent?
- Laravel 9 Eloquent Mutators and Accessors Example
- Laravel Eloquent Select Single Column to Array Example
- Laravel Eloquent Group By Year with Sum Example
- Laravel Eloquent Model Custom Function Example
- Laravel Copy Record using Eloquent Replicate Example
- Laravel Eloquent withMin(), withMax() and withAvg() Example
- Laravel Eloquent withSum() and withCount() Example
- Laravel Eloquent updateOrCreate Example
- Laravel Eloquent inRandomOrder() Method Example
- Laravel Pluck Method Example | Laravel Pluck()
- Laravel Dynamic Dependent Dropdown Example
- Laravel Select with Count Query with Group By Example
- Laravel Select with Sum Query Example
- Laravel Join with Subquery in Query Builder Example