Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ModelsTableSeeder extends Seeder {
- public function run()
- {
- Eloquent::unguard();
- // Uncomment the below to wipe the table clean before populating
- //DB::table('models')->delete();
- // Uncomment the below if you need to reset the id autoincrement counter
- //DB::statement('ALTER TABLE models AUTO_INCREMENT=1');
- function csv_to_array($filename='', $delimiter=';')
- {
- if(!file_exists($filename) || !is_readable($filename))
- return FALSE;
- $header = NULL;
- $data = array();
- if (($handle = fopen($filename, 'r')) !== FALSE)
- {
- while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
- {
- if(!$header)
- $header = $row;
- else
- $data[] = array_combine($header, $row);
- }
- fclose($handle);
- }
- return $data;
- }
- /****************************************
- * CSV FILE SAMPLE *
- ****************************************/
- // id,subdireccion_id,idInterno,area
- // ,1,4,AREA MALAGA OCC
- // ,1,2,AREA MALAGA N/ORIENT
- $csvFile = public_path().'/models.csv';
- $models = csv_to_array($csvFile);
- // Uncomment the below lines to run the seeder
- // foreach ($models as $model)
- // {
- // Models::create($model);
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement