ItSolutionStuff.com

Laravel - Call to Undefined Method Illuminate\Database\Query\Builder::lists() Solved

By Hardik Savani • November 5, 2023
Laravel

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.....

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Find Multiple Ids using Laravel Eloquent?

Read Now →

Laravel 9 Eloquent Mutators and Accessors Example

Read Now →

Laravel Eloquent Select Single Column to Array Example

Read Now →

Laravel Eloquent Group By Year with Sum Example

Read Now →

Laravel Eloquent Model Custom Function Example

Read Now →

Laravel Copy Record using Eloquent Replicate Example

Read Now →

Laravel Eloquent withMin(), withMax() and withAvg() Example

Read Now →

Laravel Eloquent withSum() and withCount() Example

Read Now →

Laravel Eloquent updateOrCreate Example

Read Now →

Laravel Eloquent inRandomOrder() Method Example

Read Now →

Laravel Pluck Method Example | Laravel Pluck()

Read Now →

Laravel Dynamic Dependent Dropdown Example

Read Now →

Laravel Select with Count Query with Group By Example

Read Now →

Laravel Select with Sum Query Example

Read Now →

Laravel Join with Subquery in Query Builder Example

Read Now →