filament-import
filament-import copied to clipboard
Importing only process one row
Hi ! :vulcan_salute:
After using this plugin, I face a problem.
I need to import data and assign it to a belongsToMany
relation, but on importing my xlsx file, only one row is processed:
This is my xlsx file:
This is the form:
N° volontaire = volunteer_id
And for each row I need to attach it on my pivot table like so:
cohort_id | volunteer_id |
---|---|
1 | 6 |
1 | 7 |
1 | 8 |
But on import he create same cohorts with only one volunteer in it:
This is the code I use:
protected function getActions(): array
{
return [
ImportAction::make()
->label('Importer une cohorte')
->fields([
TextInput::make('name')
->required()
->label('Nom de la cohorte'),
TextInput::make('description')
->required()
->label('Description de la cohorte'),
ImportField::make('volunteer_id')
->label('Colonne N° de volontaire'),
])->mutateAfterCreate(function (Model $model, $row) {
$volunteer_id = $row['volunteer_id'];
Volunteer::find($volunteer_id)->cohorts()->save($model);
}),
];
}
Did I miss something in the doc ? Or it is a normal behavior ?
Thanks for reading,
Best regards !