lundi 29 février 2016

Laravel 5 - Not seeding a table when using php artisan db:seed, but works fine when php artisan db:seed --class is used

I entered php artisan db:seed but it skip seeding CountriesRetailerSeeder.

It seeds when I do it manually.

php artisan db:seed --class=CountriesRetailerSeeder

How will I be able to run it in php artisan db:seed along with the other seeders ?

here's the code in my CountriesRetailerSeeder

use Illuminate\Database\Seeder;
use League\Csv\Reader;
use App\CountryRetailer;

public function run()
{
     DB::table('country_retailer')->truncate();
     $file = base_path().'/database/seeds/country_retailer_csv.csv';
     $reader = Reader::createFromPath($file);

     $data = array();
     $count_elements = 0;
     foreach($reader as $index => $row)
     {
         $data[$count_elements] = array('country'=>$row[0],'original_header'=>$row[1],'count'=>$row[2],
         'channel'=>$row[3],'retailer'=>$row[4],
         'website'=>$row[6],'contacts'=>$row[7],'notes'=>$row[8]);

         $count_elements++;
     }
     $cr = new CountryRetailer;
     $cr::insert($data);
}

Take not that all of those 2000 rows of data is from a csv file.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire