8000 Update docs to include nested mapped import (#214) · anthony-dee/laravel-excel-docs@cf3802f · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit cf3802f

Browse files
author
biber
authored
Update docs to include nested mapped import (SpartnerNL#214)
1 parent c10aa2f commit cf3802f

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

4.x/imports/mapped-cells.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use App\User;
2121
use Maatwebsite\Excel\Concerns\ToModel;
2222
use Maatwebsite\Excel\Concerns\WithMappedCells;
2323

24-
class UsersImport implements WithMappedCells, ToModel
24+
class UsersImport implements WithMappedCells, ToModel
2525
{
2626
public function mapping(): array
2727
{
@@ -30,7 +30,7 @@ class UsersImport implements WithMappedCells, ToModel
3030
'email' => 'B2',
3131
];
3232
}
33-
33+
3434
public function model(array $row)
3535
{
3636
return new User([
@@ -44,3 +44,43 @@ class UsersImport implements WithMappedCells, ToModel
4444
::: warning
4545
This concern is not meant to map **columns**, only specific **cell** reference are allowed.
4646
:::
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.

0 commit comments

Comments
 (0)
0