8000
File tree Expand file tree Collapse file tree 1 file changed +42
-2
lines changed Expand file tree Collapse file tree 1 file changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ use App\User;
21
21
use Maatwebsite\Excel\Concerns\ToModel;
22
22
use Maatwebsite\Excel\Concerns\WithMappedCells;
23
23
24
- class UsersImport implements WithMappedCells, ToModel
24
+ class UsersImport implements WithMappedCells, ToModel
25
25
{
26
26
public function mapping(): array
27
27
{
@@ -30,7 +30,7 @@ class UsersImport implements WithMappedCells, ToModel
30
30
'email' => 'B2',
31
31
];
32
32
}
33
-
33
+
34
34
public function model(array $row)
35
35
{
36
36
return new User([
@@ -44,3 +44,43 @@ class UsersImport implements WithMappedCells, ToModel
44
44
::: warning
45
45
This concern is not meant to map ** columns** , only specific ** cell** reference are allowed.
46
46
:::
47
+
48
+ ## Multi-demensional Mapping
49
+
50
+ In case you have repeating data in your table, e. g. a spreadsheet looking like this:
51
+
52
+ | Team 1 | | Team 2| |
53
+ | -| -| -| -|
54
+ | Max | 2 | Peter | 3 |
55
+ | Annie | 0 | Alex | 1 |
56
+
57
+ you are also able to define cell coordinates in a nested array:
58
+
59
+ ``` php
60
+ public function mapping(): array
61
+ {
62
+ return [
63
+ 'team1' => [
64
+ [
65
+ 'name' => 'A2',
66
+ 'score' => 'B2',
67
+ ],
68
+ [
69
+ 'name' => 'A3',
70
+ 'score' => 'B3',
71
+ ],
72
+ ],
73
+ 'team2' => [
74
+ [
75
+ 'name' => 'C2',
76
+ 'score' => 'D2',
77
+ ],
78
+ [
79
+ 'name' => 'C3',
80
+ 'score' => 'D3',
81
+ ],
82
+ ],
83
+ ];
84
+ }```
85
+
86
+ Note that an array of the same form will be returned.
You can’t perform that action at this time.
0 commit comments