Anto
Anto
FFilament
Created by Anto on 9/20/2023 in #❓┊help
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":
protected function beforeFill(): void
{
$record = $this->getRecord();
$record->makeVisible(['outstanding_order']);
}

protected function afterFill(): void
{
$this->refreshFormData(['outstanding_order']);
}
protected function beforeFill(): void
{
$record = $this->getRecord();
$record->makeVisible(['outstanding_order']);
}

protected function afterFill(): void
{
$this->refreshFormData(['outstanding_order']);
}
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!
5 replies