Problem displaying laravel model $hidden fields in Filament forms
Hello,
FIlament version: 3.0.53
PHP version: 8.1.4
My problem is that I have certain fields in my Laravel model set to be hidden using the $hidden property. When I try to edit these fields using Filament forms, they are not visible, as expected. I'm looking for a way to make them visible in the Filament forms without altering the $hidden property globally.
The easy but not clean solution is duplicate the model without the $hidden property and use the duplicated model for Filament.
The approach I'm currently taking, in my EditRecord class I added two methods "beforeFill" and "afterFill":
Note: I added the refreshFormData in the afterFill() because after looking into the fillFormWithDataAndCallHooks method, $data remains unchanged after calling the beforeFill hook.
Perhaps if there was a $this->callHook('beforeFetchingAttributes'); just before executing $data = $this->getRecord()->attributesToArray(); in the fillForm() method, it might provide more flexibility for such scenarios. I understand that having too many hooks can lead to complexity, and there might be reasons for not having implemented it this way. Just a suggestion for consideration 😅
Does anyone have a better solution or suggestions for this problem? Any help would be appreciated. Thanks in advance!
Solution:Jump to solution
I had a similar need,
In my case I wanted to display a hidden property in a form.
I ended up using:
```
TextInput::make('secret')...
2 Replies
Solution
I had a similar need,
In my case I wanted to display a hidden property in a form.
I ended up using:
->formatStateUsing worked for me, thanks!