Skip to content

Commit c855d90

Browse files
author
Jared Malcolm
committed
Added property to trim value from CSV
1 parent 9b6b261 commit c855d90

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Flynsarmy/CsvSeeder/CsvSeeder.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ class CsvSeeder extends Seeder
6161
*/
6262
public $offset_rows = 0;
6363

64+
/**
65+
* Can be used to tell the import to trim any leading or trailing white space from the column;
66+
*
67+
* @var bool
68+
*/
69+
public $should_trim = false;
70+
6471

6572
/**
6673
* The mapping of CSV to DB column. If not specified manually, the first
@@ -238,7 +245,7 @@ public function readRow( array $row, array $mapping )
238245
public function insert( array $seedData )
239246
{
240247
try {
241-
DB::table($this->table)->insert($seedData);
248+
DB::table($this->table)->insert($this->should_trim ? trim($seedData) : $seedData);
242249
} catch (\Exception $e) {
243250
Log::error("CSV insert failed: " . $e->getMessage() . " - CSV " . $this->filename);
244251
return FALSE;

0 commit comments

Comments
 (0)