how to mutate data in record in relation in form
I have a userResource for User table which has a metadata table with its foreign-key.
I have added form fields of metadata with Users fields in one form like this:
I want to mutate "experience" field of metadata before filling this form.
I tried
mutateRecordDataUsing
, but it is not working, even dd($data)
is not triggering.
How do I do this?8 Replies
Can you try mutateFormDataUsing ?
I guess
mutateFormDataUsing
is to mutate data before storing it. I also tried that but it is not workingahh sorry, before filling the form...
try using
->saveRelationShipDataUsing()
oh, before, then load instead of savemutateRecordDataUsing should work I think
What about an accessor? https://laravel.com/docs/10.x/eloquent-mutators#defining-an-accessor
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
mutateRecordDataUsing
works fine on RelationManager for metadata
table but it is not working on UserResource.You can try an accessor I think...
Yes Thanks, That works, but that applies mutation globally. If any other part of application tries to access that field than it will get modified data. In that case I have to remove my RelationManagers mutators. I was looking to mutate locally.