Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

php - Call to undefined method IlluminateDatabaseQueryBuilder::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 IlluminateDatabaseQueryBuilder::lists() in /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2431
Stack trace:
#0 [internal function]: IlluminateDatabaseQueryBuilder->__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): IlluminateDatabaseEloquentBuilder->__call('lists', Array)
#3 /home/vagrant/Code/vendor/cviebrock/eloquent-sluggable/src/SluggableTrait.php(170): AppUser->getExistingSlugs('nouseratnouser-...')
#4 /home/vagrant/Code/vendor/cviebrock/eloquent-sluggable/src/SluggableTrait.php(312): AppUser->makeSlugUnique('nouseratnouser-...')
#5 /home/vagrant/Code/vendor/cviebrock/eloquent-sluggable/src/SluggableServiceProvider.php(72): AppUser->sluggify()
#6 [internal function]: CviebrockEloquentSluggableSluggableServiceProvider->CviebrockEloquentSluggable{closure}(Object(AppUser))
#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): IlluminateEventsDispatcher->fire('eloquent.saving...', Array, true)
#9 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1664): IlluminateEventsDispatcher->until('eloquent.saving...', Object(AppUser))
#10 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1456): IlluminateDatabaseEloquentModel->fireModelEvent('eloquent.saving...')
#11 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(562): IlluminateDatabaseEloquentModel->save()
#12 /home/vagrant/Code/database/seeds/UserSeeder.php(34): IlluminateDatabaseEloquentModel::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): IlluminateDatabaseSeeder->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): IlluminateDatabaseConsoleSeedsSeedCommand->IlluminateDatabaseConsoleSeeds{closure}()
#17 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(64): IlluminateDatabaseEloquentModel::unguarded(Object(Closure))
#18 [internal function]: IlluminateDatabaseConsoleSeedsSeedCommand->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): IlluminateContainerContainer->call(Array)
#21 /home/vagrant/Code/vendor/symfony/console/Command/Command.php(256): IlluminateConsoleCommand->execute(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#22 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): SymfonyComponentConsoleCommandCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#23 /home/vagrant/Code/vendor/symfony/console/Application.php(818): IlluminateConsoleCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#24 /home/vagrant/Code/vendor/symfony/console/Application.php(186): SymfonyComponentConsoleApplication->doRunCommand(Object(IlluminateDatabaseConsoleSeedsSeedCommand), Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#25 /home/vagrant/Code/vendor/symfony/console/Application.php(117): SymfonyComponentConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#26 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(111): SymfonyComponentConsoleApplication->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#27 /home/vagrant/Code/artisan(35): IlluminateFoundationConsoleKernel->handle(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#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???

question from:https://stackoverflow.com/questions/39114249/call-to-undefined-method-illuminate-database-query-builderlists-when-seeding

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...