Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined method Illuminate\Database\Query\Builder::lists() when seeding after updating to Laravel 5.3

I'm updating to laravel 5.3, and I get this message:

[2016-08-23 23:12:39] local.ERROR: BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::lists() in /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2431
Stack trace:
#0 [internal function]: Illuminate\Database\Query\Builder->__call('lists', Array)
#1 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1423): call_user_func_array(Array, Array)
#2 /home/vagrant/Code/vendor/cviebrock/eloquent-sluggable/src/SluggableTrait.php(254): Illuminate\Database\Eloquent\Builder->__call('lists', Array)
#3 /home/vagrant/Code/vendor/cviebrock/eloquent-sluggable/src/SluggableTrait.php(170): App\User->getExistingSlugs('nouseratnouser-...')
#4 /home/vagrant/Code/vendor/cviebrock/eloquent-sluggable/src/SluggableTrait.php(312): App\User->makeSlugUnique('nouseratnouser-...')
#5 /home/vagrant/Code/vendor/cviebrock/eloquent-sluggable/src/SluggableServiceProvider.php(72): App\User->sluggify()
#6 [internal function]: Cviebrock\EloquentSluggable\SluggableServiceProvider->Cviebrock\EloquentSluggable\{closure}(Object(App\User))
#7 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(221): call_user_func_array(Object(Closure), Array)
#8 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(164): Illuminate\Events\Dispatcher->fire('eloquent.saving...', Array, true)
#9 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1664): Illuminate\Events\Dispatcher->until('eloquent.saving...', Object(App\User))
#10 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1456): Illuminate\Database\Eloquent\Model->fireModelEvent('eloquent.saving...')
#11 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(562): Illuminate\Database\Eloquent\Model->save()
#12 /home/vagrant/Code/database/seeds/UserSeeder.php(34): Illuminate\Database\Eloquent\Model::create(Array)
#13 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(39): UserSeeder->run()
#14 /home/vagrant/Code/database/seeds/DatabaseSeeder.php(37): Illuminate\Database\Seeder->call('UserSeeder')
#15 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(63): DatabaseSeeder->run()
#16 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2279): Illuminate\Database\Console\Seeds\SeedCommand->Illuminate\Database\Console\Seeds\{closure}()
#17 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(64): Illuminate\Database\Eloquent\Model::unguarded(Object(Closure))
#18 [internal function]: Illuminate\Database\Console\Seeds\SeedCommand->fire()
#19 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
#20 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#21 /home/vagrant/Code/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /home/vagrant/Code/vendor/symfony/console/Application.php(818): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /home/vagrant/Code/vendor/symfony/console/Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Database\Console\Seeds\SeedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /home/vagrant/Code/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(111): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 /home/vagrant/Code/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#28 {main}  

I checked the code that cause it:

        User::create([
        'name' => 'No User',
        'email' => '[email protected]',
        'password' => bcrypt('0'),
        'provider' => '0',
    ]);

I don't understand why.

If I comment it, I get the same problem in another file:

        Tournament::create([
        'user_id' => 1,
        'name' => "name",
        'dateIni' =>  $dateIni,
        'dateFin' =>  $dateIni,
    ]);

I've made a global search of "lists" without success...

Any idea why is it happening???

like image 812
Juliatzin Avatar asked Aug 24 '16 04:08

Juliatzin


3 Answers

You can use method pluck. Method lists is removed in Laravel 5.3. I changed lists('key')->all() to pluck('key')->all() and it's working now.

like image 141
Sang Nguyen Avatar answered Nov 16 '22 12:11

Sang Nguyen


Laravel 5.3, the lists() method is removed in favour of the pluck() method. For Example:

$userList = App\User::pluck('name', 'id');
like image 26
Mahbub Avatar answered Nov 16 '22 12:11

Mahbub


lists() was deprecated. Use pluck() instead.

The lists method on the Collection, query builder and Eloquent query builder objects has been renamed to pluck. The method signature remains the same.

https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0

like image 7
Alexey Mezenin Avatar answered Nov 16 '22 13:11

Alexey Mezenin