I am trying to get the value of some cells in a sheet from an excel file. According to the docs (https://docs.laravel-excel.com/3.1/imports/mapped-cells.html) I need to use WithMappedCells and their example code is:
public function mapping(): array
{
return [
'name' => 'B1',
'email' => 'B2',
];
}
public function model(array $row)
{
return new User([
'name' => $row['name'],
'email' => $row['email'],
]);
}
Here is my spreadsheet:
In my import file I have this mapping
public function mapping(): array
{
return [
'type_key' => 'A1',
'isDraft_key' => 'A2',
'isPublished_key' => 'A3',
'type' => 'B1',
'isDraft' => 'B2',
'isPublished' => 'B3',
];
}
On their github I found this solution: https://github.com/Maatwebsite/Laravel-Excel/issues/1836#issuecomment-431808465
public function map($row)
{
return new Veiling([
'name' => $row['name'],
'nummer' => $row['nummer'],
'info' => $row['info'],
]);
}
However, this still tried to add it to a Model. I noticed that it used $row So I tried is this:
public function map($row): array {
Log::info($row['type_key']);
return $row;
}
But I get this error:
Undefined index: type_key
How do I simple get those values from those specific cells so I can perform some checks on them?
Edit: When I log out just $row I get:
array (
0 =>
array (
'type' => 'isDraft',
'report.' => 'TRUE',
),
0 =>
array (
'type' => 'isPublished',
'report.' => 'FALSE',
),
)
As you can see, the data is there but the mapping is not correct. I have checked and I am using :
use Maatwebsite\Excel\Concerns\WithMappedCells;
use Maatwebsite\Excel\Concerns\WithMapping;
at the top of my file and am making sure my class implements these:
Import Implements WithMapping, WithMappedCells {
