F
Filamentβ€’2w ago
aldec

Get form state of 'parent' form inside a relationship

I have a helper function setting a label or visibility of form fields based spatie settings. Which setting is applicable is dependent on a property/form component. Inside my rather complex form I have multiple relationships. The helper functions try access the property of the 'parent' form via $get('myProperty'), but it is not accessible anymore. Can I traverse these form states?
function fieldVisibility(string $fieldKey): Closure
{
return function (callable $get) use ($fieldKey) {
$settings = app(RoadworksSettings::class);
$applicationType = $get('type');
$applicationTypeKey = Str::slug($applicationType, '_');
return $settings->fieldConfigurations[$applicationTypeKey][$fieldKey]['visible'] ?? true;
};
}
function fieldVisibility(string $fieldKey): Closure
{
return function (callable $get) use ($fieldKey) {
$settings = app(RoadworksSettings::class);
$applicationType = $get('type');
$applicationTypeKey = Str::slug($applicationType, '_');
return $settings->fieldConfigurations[$applicationTypeKey][$fieldKey]['visible'] ?? true;
};
}
Solution:
$get('../type') or ../../type etc
Jump to solution
3 Replies
toeknee
toekneeβ€’2w ago
traverse πŸ˜‰
Solution
toeknee
toekneeβ€’2w ago
$get('../type') or ../../type etc
aldec
aldecOPβ€’2w ago
Yeah... that makes sense πŸ™ˆ

Did you find this page helpful?