Validations

Unless you like to live dangerously, any Atomic fields that are displayed on the creation / update screens will need some validation. Thankfully, it's a cinch to attach all of the Laravel validation rules you're familiar with to your Atomic fields. Let's get started.

Attaching Rules

When defining a field on a Model, you may use the rules method to attach validation rules to the field:

Text::make('Name')
    ->rules('required', 'max:255')
1
2

Creation Rules

If you would like to define rules that only apply when a model is being created, you may use the creationRules method:

Text::make('Username')
    ->rules('required', 'max:255')
    ->creationRules('unique:users,username')
    ->updateRules('unique:users,username,{{modelID}}')
1
2
3
4

Update Rules

If you would like to define rules that only apply when a model is being updated, you may use the updateRules method:

Text::make('Username')
    ->rules('required', 'max:255')
    ->creationRules('unique:users,username')
    ->updateRules('unique:users,username,{{modelID}}')
1
2
3
4