Call to undefined method Illuminate\Database\Query\Builder::lists() when seeding after updating to Laravel 5.3
Upgrading from Laravel 5.2 to Laravel 5.3 often triggers a BadMethodCallException regarding an undefined method lists(). This error typically surfaces during database seeding, specifically when using third-party packages that rely on legacy query syntax. The stack trace points to Cviebrock\EloquentSluggable, indicating that the package is attempting to use a helper method that was deprecated and subsequently removed in the core framework.
In Laravel 5.3, the lists() method was officially removed from the Illuminate\Database\Query\Builder class. This change aligns with the introduction of pluck(). While pluck() returns an array of values without keys (or a flat array), lists() returned an associative array mapping primary keys to values. The removal was part of a broader cleanup to encourage more explicit query building patterns and to reduce confusion between key-value pairs and simple value lists.
The root cause in your scenario is that the eloquent-sluggable package version you are using still references the old lists() method within its trait logic. Specifically, the error occurs inside SluggableTrait.php, where the code attempts to generate a unique slug by querying existing slugs for a user or tournament. When the seeder calls User::create(), Laravel fires the eloquent.saving event. The package's service provider listens for this event and triggers logic that eventually hits the deprecated method.
To resolve this, you must update the eloquent-sluggable package to a version compatible with Laravel 5.3+. If you are locked into an older version of the package or cannot upgrade immediately, you have two primary options:
Upgrade the Package: Run the following command in your project root:
composer update cviebrock/eloquent-sluggableThis will pull a version that implements
pluck()instead oflists(), eliminating the exception and ensuring compatibility with the new query builder API.Patch the Trait: If upgrading is not feasible, you must manually patch the source code of the package in your
vendordirectory. Locate/vendor/cviebrock/eloquent-sluggable/src/SluggableTrait.phpand find any instance wherelists()is called. Replace the call withpluck(). For example:// Old code causing the error $slugs = User::where('slug', $slug)->lists('id'); // Updated code for Laravel 5.3+ $slugs = User::where('slug', $slug)->pluck('id');You will likely need to apply this change in multiple locations within the trait, specifically inside methods like
makeSlugUniqueorgetExistingSlugs, depending on how the package utilizes the result. Ensure you replace all occurrences to prevent intermittent failures.
It is also worth noting that while pluck() and lists() behave similarly for simple queries, they differ when a column alias is used or when multiple columns are selected. If your application relies on specific associative array structures from these methods, switching to pluck() may require adjustments in how you handle the returned data, though for basic ID retrieval, the behavior remains consistent enough for most migration cases.
Finally, ensure that your database migrations and seeders do not rely on deprecated query builder methods beyond just lists(). The upgrade path to Laravel 5.3 involves auditing third-party dependencies for similar deprecations, as many packages released around 5.2 did not immediately update their internal logic to support the new core standards.