forked from nathalie/pedi2
36 lines
883 B
PHP
36 lines
883 B
PHP
|
<?php
|
||
|
|
||
|
use Illuminate\Database\Seeder;
|
||
|
use League\Csv\Reader;
|
||
|
|
||
|
class ProductoSeeder extends Seeder
|
||
|
{
|
||
|
/**
|
||
|
* Run the database seeds.
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function run()
|
||
|
{
|
||
|
$csv = Reader::createFromPath(resource_path('csv/productos.csv'), 'r');
|
||
|
$csv->setDelimiter("|");
|
||
|
$csv->setEnclosure("'");
|
||
|
$csv->setHeaderOffset(0);
|
||
|
$registros = $csv->getRecords();
|
||
|
$toInsert = [];
|
||
|
|
||
|
foreach($registros as $registro){
|
||
|
$toInsert[] = [
|
||
|
'categoria' => $registro['categoria'],
|
||
|
'nombre' => $registro['producto'],
|
||
|
'precio' => $registro['precio']
|
||
|
];
|
||
|
}
|
||
|
|
||
|
foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||
|
{
|
||
|
DB::table('productos')->insert($chunk);
|
||
|
}
|
||
|
}
|
||
|
}
|