geniusfactor / fibr-csv
A Laravel-based package to make it easy for bulk imports of CSV data; A wrapper for flynsarmy/csv-seeder
This package's canonical repository appears to be gone and the package has been frozen as a result.
1.0.1
2018-02-26 12:05 UTC
Requires
- flynsarmy/csv-seeder: 1.0.*
- laravel/framework: ^5.6
This package is not auto-updated.
Last update: 2020-07-06 20:25:38 UTC
README
A simple wrapper class for flynsarmy/csv-seeder
; Makes it easier to do bulk imports of CSV files in one seeder.
Release History
- 1.0.0 - Initial release.
Installation
In your project, bring in the dependency with Composer
composer require 'geniusfactor/fibr-csv'
Adding the following entry to your .env
file will report each CSV file imported (defaults to false
)
DB_CSV_VERBOSE_OUTPUT=true
Usage
- Create a new Seeder (
php artisan make:seeder {SeederName}
) - Change the Seeder to inherit from
\FIBR\Seeders\CsvSeed
- Define an array of the table names and paths (relative to the project root) to your associated CSV files.
- Add your seeder to your DatabaseSeeder class
php artisan migrate db:seed
to test!
Code Sample
Your Seeder can look as simple as this:
<?php
class seed_geo_tables extends \FIBR\Seeders\CsvSeed
{
public function __construct()
{
}
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$tables = array(
'countries' => 'database/csv/common/geo/countries.csv',
'territories' => 'database/csv/common/geo/territories.csv',
'municipalities' => 'database/csv/common/geo/municipalities.csv',
'regions' => 'database/csv/common/geo/regions.csv',
);
$this->bulkImport($tables);
}
}
Special Thanks
- Taylor Ottwell for the awesome Laravel Framework
- Flynnsarmy for the CSV Seeder project that this wrapper is based upon