F
Filamentβ€’16mo ago
Daniel

Form state for fields with relationship

How can I get the submitted data for fields which have a relationship defined? When using $data = $this->form->getState(); in forms submit I only get the data of fields without relationships. I need the whole form data (in a frontend form) to "park" it in session and use it again after user has either logged in or registered.
29 Replies
Dan Harrin
Dan Harrinβ€’16mo ago
after getState() is called, the relations are saved to the $record so you can access the data with $record->relationshipName
Daniel
Danielβ€’16mo ago
also without saving the model/record at this point?
Dan Harrin
Dan Harrinβ€’16mo ago
why use relationship() at all if you dont want us to do anything with it?
Daniel
Danielβ€’16mo ago
i need the saving process after the user has logged in. the user can make a booking with nested relations and after he/she has logged in or registered i wanted to save the booking when not using the relationship() i do have to make it all maunally
Dan Harrin
Dan Harrinβ€’16mo ago
you could use ->relationship('xxx')->dehydrated()
Daniel
Danielβ€’16mo ago
alright. does this also work for nested relationships?
Dan Harrin
Dan Harrinβ€’16mo ago
probably
Daniel
Danielβ€’16mo ago
i think there's still the bug with nested savings
Dan Harrin
Dan Harrinβ€’16mo ago
make sure to put it next to all relationship() calls that should be dehydrated i fixed it though...
Daniel
Danielβ€’16mo ago
already released?
Dan Harrin
Dan Harrinβ€’16mo ago
i've just released it in 2.17.22. wait a few mins https://github.com/filamentphp/filament/pull/6092/files
Daniel
Danielβ€’16mo ago
awesome! no matter hoe deep the nesting is?
Dan Harrin
Dan Harrinβ€’16mo ago
i hope so
Daniel
Danielβ€’16mo ago
i do have 3 levels i will try it out πŸ™‚ no, still not working in my case nothing changed with this release
Dan Harrin
Dan Harrinβ€’16mo ago
did you open the issue originally?
Daniel
Danielβ€’16mo ago
yes
Dan Harrin
Dan Harrinβ€’16mo ago
i used that repo to test the fix are you sure the changes i made are in /vendor
Daniel
Danielβ€’16mo ago
ah ok - i will have a look when iβ€˜m home again. my relationship is defined as morphable
Dan Harrin
Dan Harrinβ€’16mo ago
i dont remember that in the project you send in the issue?
Daniel
Danielβ€’16mo ago
i will set this up ok? do you think it would make a difference what type the relation is of? hey @Dan Harrin i've looked it up and the repo i've provided also had the relationships defined as morphables:
Daniel
Danielβ€’16mo ago
Dan Harrin
Dan Harrinβ€’16mo ago
can you point to a specific use case that doesnt work because i used it to make my original fix
Daniel
Danielβ€’16mo ago
in my screenshot "phone" is always empty - now even the "update" does not work anymore tried put in the provided repo here are the models:
Daniel
Danielβ€’16mo ago
GitHub
filament-test/app/Models at main Β· danielbehrendt/filament-test
Contribute to danielbehrendt/filament-test development by creating an account on GitHub.
Daniel
Danielβ€’16mo ago
and here the resource
Daniel
Danielβ€’16mo ago
user -> person (works) -> contact (works not)
Dan Harrin
Dan Harrinβ€’16mo ago
i have reopened the issue, this is a complex problem so you will have to be patient with the fix
Daniel
Danielβ€’16mo ago
alright, no problem. i will wait patiently (as it will be an enormous boost and will provide a lot of flexibility) πŸ˜‰