我已经将我的代码从Laravel 5.2移到了5.3,一切正常,除非我运行DatabaseSeeder。这在Laravel 5.2中完美运行,现在当我尝试在5.3中运行php artisan db:seed
时,当Seeder使用Faker时我得到此错误:
[BadMethodCallException]
Call to undefined method Illuminate\Database\Query\Builder::lists()
似乎所有东西都安装得正确。
代码示例:
<?php
use App\Models\Gallery;
use App\Models\GalleryImage;
use Illuminate\Database\Seeder;
class GalleryImageTableSeeder extends Seeder
{
public function run()
{
DB::table('gallery_images')->delete();
$faker = Faker\Factory::create();
$gallery = Gallery::lists('id')->All();
foreach(range(1, 98) as $index) {
GalleryImage::create([
'page_id' => null,
'gallery_id' => $faker->randomElement($gallery),
'alt' => 'Image description',
'large' => '201508183828fh5ntu80ub-or.jpg',
'medium' => '201508183828fh5ntu80ub-lg.jpg',
'thumbnail' => '201508183828fh5ntu80ub-th.jpg',
'order' => 1,
'cover' => false,
'visibility' => 'visible',
]);
}
}
}
答案 0 :(得分:0)
最后我发现它是mysql。需要将list
更改为pluck
示例:
$gallery = Gallery::pluck('id')->All();