Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing only process one row #78

Open
JibayMcs opened this issue Feb 14, 2023 · 0 comments
Open

Importing only process one row #78

JibayMcs opened this issue Feb 14, 2023 · 0 comments

Comments

@JibayMcs
Copy link

Hi ! 🖖

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant