How to handle selected relations during creating a record in handleRecordCreation
When I try to create a new User from this form I don't see the selected relations as ID's in the handleRecordCreation so that I can manually attach anything needed.
This is how I load them
If I use the
options
instead of relationship
and load them in manually I get the needed data inside of the handleRecordCreation method but is that the only way to do it?Solution:Jump to solution
I did end up using the following
```
private static function buildRolesField(): Select
{...
11 Replies
if you use relationship then they are automatically created.
Please explain in more detail what you are trying to do?
I'm using teams and laravel shield is not supporting them, so when I try to enter a new record in the user table with permissions I get the error from the screenshot. This is why I want to handle the permission creation manually.
Thank you
So you need to read the relationship docs 😉 you need to mutation the relationship save method
I was looking at the selection docs 😄 but I guess I need to look there too, thanks
I will go and have a look at it
Since you are here I can see that I need to attach this after the schema, but I get the same error again.
https://filamentphp.com/docs/3.x/forms/fields/repeater#mutating-related-item-data-before-creating
It's not hitting the callback, it throws an error before that.
shouldn't you use
mutateRelationshipDataBeforeCreateUsing
in the Roles/Permissions fields?
If you add ->dehydrated(true)
to the fields, they will be available in the $data
arrayI will try the dehydrate tomorrow, thank you
I've tried both but none of them worked.
share the whole code that you are using
This is the full UserResource @Leandro Ferreira, thank you
Solution
I did end up using the following