Conditional Fields


Field conditions can be used to display fields when a model attribute has a certain value. Individual fields or field groups can be made dependent on model values.

radio conditions


The following example shows an input field that only gets displayed if model attribute type has the value news:

        'news' => 'News',
        'blog' => 'Blog',

    ->when('type, 'news');

A varity of conditions are available for any field:

Condition Description
$field->when('type', 'foo') Matches the exact given value.
$field->whenNot('type', 'foo') When field doesnt match the given value.
$field->whenContains('type', 'foo') Matches the given substring or array value.
$field->whenNotContains('type', 'foo') When field doesnt contain the given value.

Conditional Groups

Conditions can also be applied to groups:

$form->group(function($form) {


})->when('type', 'news');

Multiple Conditions

You may chain as many conditions in a row by adding or to the desired condition:

    ->when($field, 'news')
    ->orWhen($field, 'blog');
Why don't you do us a favor by leaving a little star on GitHub