Skip to content

Commit 6ee1358

Browse files
committed
Update readme
1 parent 392b7be commit 6ee1358

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

readme.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,47 @@ In addition to setting the database table and CSV filename, two other configurat
5454
- `insert_chunk_size` (int 500) An SQL insert statement will trigger every `insert_chunk_size` number of rows while reading the CSV
5555
- `csv_delimiter` (string ,) The CSV field delimiter.
5656
- `hashable` (string password) Hash the hashable field, useful if you are importing users and need their passwords hashed. Uses `Hash::make()`. Note: This is EXTREMELY SLOW. If you have a lot of rows in your CSV your import will take quite a long time.
57+
- `offset_rows` (int 0) How many rows at the start of the CSV to ignore. Warning: If used, you probably want to set a mapping as your header row in the CSV will be skipped.
58+
- `mapping` (array []) Associative array of csvCol => dbCol. See examples section for details. If not specified, the first row (after offset) of the CSV will be used as the mapping.
5759

58-
For example if you have a CSV with pipe delimited values, your constructor seed constructor will look like so:
60+
61+
### Examples
62+
CSV with pipe delimited values:
63+
64+
public function __construct()
65+
{
66+
$this->table = 'users';
67+
$this->csv_delimiter = '|';
68+
$this->filename = base_path().'/database/seeds/csvs/your_csv.csv';
69+
}
70+
71+
Specifying which CSV columns to import:
72+
73+
public function __construct()
74+
{
75+
$this->table = 'users';
76+
$this->csv_delimiter = '|';
77+
$this->filename = base_path().'/database/seeds/csvs/your_csv.csv';
78+
$this->mapping = [
79+
0 => 'first_name',
80+
1 => 'last_name',
81+
5 => 'age',
82+
];
83+
}
84+
85+
Skipping the CSV header row (Note: A mapping is required if this is done):
5986

6087
public function __construct()
6188
{
62-
$this->table = 'your_table';
89+
$this->table = 'users';
6390
$this->csv_delimiter = '|';
6491
$this->filename = base_path().'/database/seeds/csvs/your_csv.csv';
92+
$this->offset_rows = 1;
93+
$this->mapping = [
94+
0 => 'first_name',
95+
1 => 'last_name',
96+
2 => 'password',
97+
];
6598
}
6699

67100
### License

0 commit comments

Comments
 (0)