›
byrcsc/laravel-checklist · 1.x
Rules add answer-dependent requirements and visibility without deleting answers that stop applying.
Conditional rules let one answer affect the work around it. A requirement rule asks for supporting material; a visibility rule decides which later items or sections still apply.
$builder->passFail('No fluid leaks')
->requireEvidenceWhen('fail', 'photo');
$builder->yesNo('Any body damage?')
->requireNoteWhen(true);The answer is accepted first. If its requirement is unmet, the package
dispatches RequirementsUnmet. Submission remains blocked until the response
has the required note or evidence type.
Changing the answer so the condition no longer matches removes the requirement.
Name an item or section, then point a rule at that key:
$builder->yesNo('Any body damage?')
->showWhen(true, 'damage-details');
$builder->section(
'Damage details',
function (TemplateBuilder $builder): void {
$builder->text('Describe the damage')->required();
},
key: 'damage-details',
);A target with at least one showWhen() rule starts hidden. It becomes visible
when any show condition matches, unless a matching hideWhen() rule hides it.
Hide wins over show.
Hiding a section hides all nested sections and items. A rule whose source item is itself hidden does not drive visibility.
| Operator | Meaning | Supported source types |
|---|---|---|
Equals | answer equals one value | every item type |
In | answer equals one value in a list | every item type |
Below | numeric answer is below a value | number, rating |
Above | numeric answer is above a value | number, rating |
use ByRcsc\LaravelChecklist\Enums\RuleOperator;
$builder->number('Temperature')
->requireNoteWhen(0, operator: RuleOperator::Below);Builder-authored comparisons are cast through the source item's handler. For
example, a pass/fail comparison of 'fail' is stored as false.
Text equality remains textual, so '0100' does not equal '100'. Number
answers compare numerically.
When an answer becomes hidden, it remains stored but changes to
is_applicable = false. The package excludes it from required-item checks,
requirement checks, scores, critical failures, and failed-item reports.
Each flip dispatches VisibilityChanged after ItemAnswered. The event and
audit order therefore explain which answer caused the branch to change.
Keys must be unique within the version. Rules cannot target their own source, point outside the version, or form a visibility cycle. Two items that hide one another are rejected, as is a longer closed loop.
These checks run during first publication and every later publication.