Mutating form data when using simple resources and wizards
I have generated a simple resource from following along in the documentation and I have created a wizard to enter a new entity into my database.
One of the values however, just comes from the user creating the record but I cannot figure out which file (Contact/ContactResource/ManageContacts) where I am supposed to make the mutation that the documentation suggestions.
A piece of constructive feedback from myself would be, although there are a lot of code examples in the docs, they don't generally say where they live / which file they should be in which for me, creates confusion slightly.
Apologies if I am missing something obvious here, first time using laravel and straight in with Filament,
Solution:Jump to solution
That should work, are you sure you have created_by_id in the fillables of the model?
10 Replies
This would be on the action it's self so where you see CreateAction::make you would chain it on here
It's not ideal jumping into filament wihtout knowing Laravel or Livewire.
Sorry I dropped a message and ran off for an appointment.
sadly, this is a work circumstance and I don't have much choice. upskilling in all areas very quickly.
So at the moment I have this:
If I chain on
mutateFormDataUsing
here, it doesn't work and I suspect it is the wrong place to do so.
Would I need to create a new method here?That is the correc place, can you provide code
Sure, the entire file looks like this:
However when I try to create a new contact, it complains that
created_by_id
has no default value (is not being provided).
Here is the form too in case it helps:
Solution
That should work, are you sure you have created_by_id in the fillables of the model?
Maybe try moving mutateFormDataUsing to the top instead createAnother prevents moving
ah that may be it! I didn't have it in the fillable array as I thought that could mean a user might be able to try and change it's value maliciously, let me give that a try however. Failing that, I will change the chain order.
If it's not in the fillable it will be it.
All values will be removed from the request that are not part of the form anyway
Also note:
https://filamentphp.com/docs/3.x/panels/getting-started#unguarding-all-models
if you are using the admin panel package
thank you! I will give that a go, currently just fixing something else and then I will be right back to it.
worked a treat thank you.