Unable to save hidden() fields to database !!
Hi,
And when I debug
The data is displayed
Do you have any idea?
Thanks.
6 Replies
Yes. That is expected. Hidden fields are not saved.
Use
mutateDataBeforeSave()
or similar form hooks to add your data.Thank you Koch,
Since I'm on the Create page, I used mutateFormDataBeforeCreate(), knowing that I already use beforeCreate() method, I'm not entirely aware of the distinction between them.
So by hiding this step(), the data is not saved to the database even using one of these two methods, but when I debug afterCreate() method, I see that the data is populated?? 🤔
Yes. It's not about the step but the hidden field. Saving logic is using
$this->form->getState()
which doesn't return hidden fields. You shouldn't rely on hidden fields anyway. They could be modified by the user. If you want to set a default you can set it in ->afterCreate()
or wherever you want to modify the data.yes, I agree with you , perfect,
so using standard Laravel code to insert data into database ( Fantastic! )
Is there a way to retrieve the inserted id of this instance?
Thank you very much for your help🤝
" you can set it in
->afterCreate()
or wherever you want to modify the data." was the key$this->record
should contain the record. Or it’s passed as the argument of the method. Not sure.Solution
Okay , thank you, i will try it