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

Second level nest not associated with parent #29

Closed
alanhartless opened this issue Jan 9, 2019 · 1 comment
Closed

Second level nest not associated with parent #29

alanhartless opened this issue Jan 9, 2019 · 1 comment

Comments

@alanhartless
Copy link

I have something similar to this setup with a Customer, Account, and User resources.

Customer:

// ...
 NestedForm::make('Accounts')
                ->hideWhenUpdating()
                ->open(true)
                ->heading('{{index}} Account')
// ... 

Account:

// ...
NestedForm::make('Users')
                ->hideWhenUpdating()
                ->heading('{{index}} User')
// ...

Customer is a oneToMany relationship with Accounts and Accounts is a ManyToMany relationship with Users. I'm able to create all three in the Customer form and the Account is associated with the Customer. But the User is not associated with the Account. Is this setup possible?

Also UI bug (maybe?), when I add a new user which has an index of 1.1, the form is collapsed no matter what I set for NestedForm::make('Users')->open()

@alanhartless
Copy link
Author

I found a work-around by doing this

NestedForm::make('Users')
                ->hideWhenUpdating()
                ->heading('{{index}} User')
                ->afterFill(
                    function ($request, $model, $attribute, $requestAttribute, $touched) {
                        $users = $touched->pluck('id')->toArray();
                        $model->users()->syncWithoutDetaching($users);
                    }
                )

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

2 participants