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 Harrin2y ago
after getState() is called, the relations are saved to the $record so you can access the data with $record->relationshipName
Daniel
DanielOP2y ago
also without saving the model/record at this point?
Dan Harrin
Dan Harrin2y ago
why use relationship() at all if you dont want us to do anything with it?
Daniel
DanielOP2y 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 Harrin2y ago
you could use ->relationship('xxx')->dehydrated()
Daniel
DanielOP2y ago
alright. does this also work for nested relationships?
Dan Harrin
Dan Harrin2y ago
probably
Daniel
DanielOP2y ago
i think there's still the bug with nested savings
Dan Harrin
Dan Harrin2y ago
make sure to put it next to all relationship() calls that should be dehydrated i fixed it though...
Daniel
DanielOP2y ago
already released?
Dan Harrin
Dan Harrin2y ago
i've just released it in 2.17.22. wait a few mins https://github.com/filamentphp/filament/pull/6092/files
Daniel
DanielOP2y ago
awesome! no matter hoe deep the nesting is?
Dan Harrin
Dan Harrin2y ago
i hope so
Daniel
DanielOP2y 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 Harrin2y ago
did you open the issue originally?
Daniel
DanielOP2y ago
yes
Dan Harrin
Dan Harrin2y ago
i used that repo to test the fix are you sure the changes i made are in /vendor
Daniel
DanielOP2y ago
ah ok - i will have a look when i‘m home again. my relationship is defined as morphable
Dan Harrin
Dan Harrin2y ago
i dont remember that in the project you send in the issue?
Daniel
DanielOP2y 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
DanielOP2y ago
Dan Harrin
Dan Harrin2y ago
can you point to a specific use case that doesnt work because i used it to make my original fix
Daniel
DanielOP2y 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
DanielOP2y ago
GitHub
filament-test/app/Models at main · danielbehrendt/filament-test
Contribute to danielbehrendt/filament-test development by creating an account on GitHub.
Daniel
DanielOP2y ago
and here the resource
Daniel
DanielOP2y ago
user -> person (works) -> contact (works not)
Dan Harrin
Dan Harrin2y ago
i have reopened the issue, this is a complex problem so you will have to be patient with the fix
Daniel
DanielOP2y ago
alright, no problem. i will wait patiently (as it will be an enormous boost and will provide a lot of flexibility) 😉

Did you find this page helpful?