File tree 3 files changed +70
-1
lines changed
3 files changed +70
-1
lines changed Original file line number Diff line number Diff line change @@ -232,7 +232,7 @@ public function createMappingFromRow(array $row): array
232
232
233
233
// skip csv columns that don't exist in the database
234
234
foreach ($ mapping as $ index => $ fieldname ) {
235
- if (!DB ::getSchemaBuilder ()->hasColumn ($ this ->table , $ fieldname )) {
235
+ if (!DB ::connection ( $ this -> connection )-> getSchemaBuilder ()->hasColumn ($ this ->table , $ fieldname )) {
236
236
if (isset ($ mapping [$ index ])) {
237
237
unset($ mapping [$ index ]);
238
238
}
Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ protected function getEnvironmentSetUp($app)
36
36
'database ' => ':memory: ' ,
37
37
'prefix ' => '' ,
38
38
]);
39
+ $ app ['config ' ]->set ('database.connections.csvSeederTest2 ' , [
40
+ 'driver ' => 'sqlite ' ,
41
+ 'database ' => ':memory: ' ,
42
+ 'prefix ' => '' ,
43
+ ]);
39
44
}
40
45
41
46
/** @test */
@@ -436,4 +441,34 @@ public function it_offsets()
436
441
'age ' => 54
437
442
]);
438
443
}
444
+ /** @test */
445
+ public function it_imports_with_non_default_connection ()
446
+ {
447
+ $ seeder = new \Flynsarmy \CsvSeeder \CsvSeeder ();
448
+ $ seeder ->table = 'tests_users2 ' ;
449
+ $ seeder ->filename = __DIR__ . '/csvs/users.csv ' ;
450
+ $ seeder ->connection = 'csvSeederTest2 ' ;
451
+ $ seeder ->hashable = [];
452
+ $ seeder ->run ();
453
+
454
+ // Make sure the rows imported
455
+ $ this ->assertDatabaseHas ('tests_users2 ' , [
456
+ 'id ' => 1 ,
457
+ 'first_name ' => 'Abe ' ,
458
+ 'last_name ' => 'Abeson ' ,
459
+ 'email ' => 'abe.abeson@foo.com ' ,
460
+ 'age ' => 50 ,
461
+ 'created_at ' => null ,
462
+ 'updated_at ' => null ,
463
+ ], 'csvSeederTest2 ' );
464
+ $ this ->assertDatabaseHas ('tests_users2 ' , [
465
+ 'id ' => 3 ,
466
+ 'first_name ' => 'Charly ' ,
467
+ 'last_name ' => 'Charlyson ' ,
468
+ 'email ' => 'charly.charlyson@foo.com ' ,
469
+ 'age ' => 52 ,
470
+ 'created_at ' => null ,
471
+ 'updated_at ' => null ,
472
+ ], 'csvSeederTest2 ' );
473
+ }
439
474
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Illuminate \Database \Migrations \Migration ;
4
+
5
+ class CreateSecondTestsUsersTable extends Migration
6
+ {
7
+ /**
8
+ * Run the migrations.
9
+ *
10
+ * @return void
11
+ */
12
+ public function up ()
13
+ {
14
+ Schema::connection ('csvSeederTest2 ' )->create ('tests_users2 ' , function ($ table ) {
15
+ $ table ->increments ('id ' );
16
+ $ table ->string ('first_name ' )->default ('' );
17
+ $ table ->string ('last_name ' )->default ('' );
18
+ $ table ->string ('email ' )->default ('' );
19
+ $ table ->string ('password ' )->default ('' );
20
+ $ table ->string ('address ' )->default ('' );
21
+ $ table ->integer ('age ' )->default (0 );
22
+ $ table ->timestamps ();
23
+ });
24
+ }
25
+ /**
26
+ * Reverse the migrations.
27
+ *
28
+ * @return void
29
+ */
30
+ public function down ()
31
+ {
32
+ Schema::connection ('csvSeederTest2 ' )->drop ('tests_users2 ' );
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments