filament-import icon indicating copy to clipboard operation
filament-import copied to clipboard

Importing only process one row

Open JibayMcs opened this issue 2 years ago • 0 comments

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: image

This is the form: image

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:

image image

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 !

JibayMcs avatar Feb 14 '23 10:02 JibayMcs