2016-08-24 92 views
1

我已經將我的代碼從Laravel 5.2移至5.3,除了運行我的DatabaseSeeder時,一切正常。這在Laravel 5.2完美的工作,現在當我嘗試運行php artisan db:seed 5.3當播種機使用法克爾我得到這個錯誤:Factory/Faker不工作在Laravel 5.3 DatabaseSeeder

[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

最後我找到了它的MySQL。需要改變listpluck

實施例:

$gallery = Gallery::pluck('id')->All();