I'm using this package: https://github.com/Flynsarmy/laravel-csv-seeder
Flynsarmy Csv seeder works fine if I manually create a file and save it as a csv, then seed my database. Artisan responds with
"Seeding: ProductsTableSeeder
Database seeding completed successfully."
However, if I save an Excel file as csv, I get the response,
"Seeding: ProductsTableSeeder"
It does not fail. No exceptions are thrown. But there is also no success message.
When I check the DB, the tables are empty.
Here's my migration 'up' method
{
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->integer('sku')->nullable();
$table->string('name');
$table->string('species')->nullable();
$table->string('fabric')->nullable();
$table->string('panel')->nullable();
$table->string('gauge_gasket')->nullable();
$table->string('type')->nullable();
$table->string('brand')->nullable();
$table->string('brand_label')->nullable();
$table->boolean('is_cjb');
$table->boolean('is_osp');
$table->boolean('is_starmark');
$table->boolean('is_vision');
$table->boolean('gasketed');;
$table->string('color');
$table->float('inside_width')->nullable();
$table->float('inside_length')->nullable();
$table->float('outside_width')->nullable();
$table->float('outside_length')->nullable();
$table->timestamps();
});
Here's my implementation of Flynsarmy Csv Seeder:
use Flynsarmy\CsvSeeder\CsvSeeder;
class ProductsTableSeeder extends CsvSeeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function __construct()
{
$this->table = 'products';
$this->filename = base_path().'/database/seeds/csvs/product_info.csv';
}
public function run()
{
// Recommended when importing larger CSVs
DB::disableQueryLog();
// Uncomment the below to wipe the table clean before populating
DB::table($this->table)->truncate();
parent::run();
}
}
Now, I suspected my issue is the csv file. I used csvlint.io and it says
*
Structural problem: Assumed header As there is no machine readable way to tell if your CSV has a header row, we have assumed that your CSV has one.
*
However, it gives this same message for the csv I manually created and that seems to work just fine.
I thought it might be a permission issue and so I did an ls -lr on my /database/seeds/csvs directory and I get
-rw-rw-r-- 1 secretname secretname 18315 Dec 19 14:07 product_info.csv
I even did what friends don't let friends do, (chmod 777), but that fixed nothing, so it isn't a permissions issue.
I've been repeatedly doing:
php artisan cache:clear
composer dumpautoload
php artisan migrate:fresh --seed
All I want to do is export from Excel to Csv and seed the database. Why is this such a problem?
Here's a sample of my csv file. I have tried with both an id column and without (since laravel adds an id and autoincrements)
sku,name,species,fabric,panel,finish,color,type,inside_width,inside_length,outside_width,outside_length,
800124,air tray casket,,,,white,,,30.5,,,,
555555,alex,metal,blue crepe,,paint,light blue,metal caskets,24.5,76.75,28.5,83,
578645,alex,metal,rosetan crepe,,paint,copper,metal caskets,24.5,76.75,28.5,83,
524785,alex,metal,oyster crepe,,paint,silver,metal caskets,24.5,76.75,28.5,83,
483959,alex,metal,oyster crepe,,paint,white,metal caskets,24.5,76.75,28.5,83,
The flynsarmy csv they give as a sample was the one that worked successfully, It's simply
id,name
1,Foo
2,Bar