fix: route dependent-field detection through visibility service (#149) - #179
fix: route dependent-field detection through visibility service (#149)#179ManukMinasyan wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes dependent custom-field detection in Filament form schemas by removing direct access to a non-existent CustomField::$visibility_conditions attribute and routing dependency discovery through the canonical CoreVisibilityLogicService, which reads settings->visibility and the current condition shape. This prevents MissingAttributeException under Eloquent strict mode and restores correct “trigger field is live” behavior when another field’s visibility depends on it.
Changes:
- Update
FormBuilder::getDependentFieldCodes()to useCoreVisibilityLogicService::getDependentFields()instead of reading a phantom model attribute. - Add a strict-mode regression test to ensure forms build without missing-attribute crashes.
- Add a feature test asserting a trigger field is marked
->live()when referenced by a dependent field’s visibility conditions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/Feature/Integration/FormBuilderStrictModeTest.php | Adds regression tests for strict-mode safety and dependent-field live detection via visibility settings. |
| src/Filament/Integration/Builders/FormBuilder.php | Routes dependent-field detection through CoreVisibilityLogicService to match the real visibility storage/shape. |
FormBuilder::getDependentFieldCodes() read $field->visibility_conditions directly, but that attribute has no column, cast, or accessor on the CustomField model. Under Model::preventAccessingMissingAttributes() (Laravel strict mode) this threw MissingAttributeException when rendering any custom-field form; without strict mode it silently returned null, so the loop never matched the current condition shape and dependent fields were never detected (their triggers were never marked live). Route through CoreVisibilityLogicService::getDependentFields(), which reads the canonical settings->visibility storage and the current VisibilityConditionData shape (field_code), resolving both the crash and the silent dependency-detection failure. Fixes #149
9b452e6 to
468aa34
Compare
|
Closing as a duplicate of #167, which takes the same Going with @crossi-dev's PR. I've rebased it onto current |
Summary
FormBuilder::getDependentFieldCodes()read$field->visibility_conditionsdirectly, but that attribute has no column, cast, or accessor on theCustomFieldmodel (visibility lives insettings->visibility). This caused two bugs:Model::preventAccessingMissingAttributes()enabled, rendering any custom-field form threwMissingAttributeException(the reported issue).null, and the expected['field' => …]shape no longer matched the currentVisibilityConditionData(field_code), so dependent fields were never detected and their trigger fields were never marked->live().The fix routes through the canonical
CoreVisibilityLogicService::getDependentFields(), which readssettings->visibilityand the current condition shape — resolving both bugs.Fixes #149.
Root-cause trace
Test plan
New
tests/Feature/Integration/FormBuilderStrictModeTest.php(both fail on the old code, pass on the fix):preventAccessingMissingAttributes()and builds the form; previously threwMissingAttributeException.CreatePostand asserts the trigger field is->live(); previously the dependency was never detected, so it was not live.Verified:
vendor/bin/pest— full suite 739 passed (0 failures)pint --test✓ ·rector --dry-run✓ (no changes) ·phpstan analyse✓ (no errors) · changed file at 100% type-coverageMissingAttributeExceptionatFormBuilder.php:48) before the fix, and rendered the full form (including custom fields) after.