Skip to content

fix: route dependent-field detection through visibility service (#149) - #179

Closed
ManukMinasyan wants to merge 1 commit into
3.xfrom
fix/form-builder-visibility-conditions-strict-mode
Closed

fix: route dependent-field detection through visibility service (#149)#179
ManukMinasyan wants to merge 1 commit into
3.xfrom
fix/form-builder-visibility-conditions-strict-mode

Conversation

@ManukMinasyan

Copy link
Copy Markdown
Collaborator

Summary

FormBuilder::getDependentFieldCodes() read $field->visibility_conditions directly, but that attribute has no column, cast, or accessor on the CustomField model (visibility lives in settings->visibility). This caused two bugs:

  1. Crash under strict mode — with Model::preventAccessingMissingAttributes() enabled, rendering any custom-field form threw MissingAttributeException (the reported issue).
  2. Silent malfunction otherwise — without strict mode the access returned null, and the expected ['field' => …] shape no longer matched the current VisibilityConditionData (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 reads settings->visibility and the current condition shape — resolving both bugs.

Fixes #149.

Root-cause trace

MissingAttributeException: attribute [visibility_conditions] … [CustomField]
  vendor/.../HasAttributes.php:527  throwMissingAttributeExceptionIfApplicable()
  src/Filament/Integration/Builders/FormBuilder.php:48  $field->visibility_conditions
  src/Filament/Integration/Builders/FormBuilder.php:77  getDependentFieldCodes()
  src/Filament/Integration/Builders/FormContainer.php:78

Test plan

New tests/Feature/Integration/FormBuilderStrictModeTest.php (both fail on the old code, pass on the fix):

  • builds a custom field form under Eloquent strict mode — enables preventAccessingMissingAttributes() and builds the form; previously threw MissingAttributeException.
  • marks a field live when another field depends on it via custom-field visibility — renders CreatePost and 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-coverage
  • Browser end-to-end in a consuming app (Filament v5): opening the New Company create form threw a 500 (MissingAttributeException at FormBuilder.php:48) before the fix, and rendered the full form (including custom fields) after.

Copilot AI review requested due to automatic review settings July 13, 2026 19:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 use CoreVisibilityLogicService::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
@ManukMinasyan
ManukMinasyan force-pushed the fix/form-builder-visibility-conditions-strict-mode branch from 9b452e6 to 468aa34 Compare July 15, 2026 20:06
@ManukMinasyan

Copy link
Copy Markdown
Collaborator Author

Closing as a duplicate of #167, which takes the same CoreVisibilityLogicService::getDependentFields() approach and was filed first (2026-06-15).

Going with @crossi-dev's PR. I've rebased it onto current 3.x so it picks up the rector 2.5.7 CI fix, and ported over the one extra thing this PR had — a regression test asserting the control field is actually made ->live() when a dependent resolves (the existing tests prove the crash is gone but not that the dependency is resolved). Credit for the fix is Charles's. Thanks @crossi-dev!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MissingAttributeException: visibility_conditions when Model::preventAccessingMissingAttributes() is enabled

2 participants