---
title: "Validation"
canonical_url: "https://handbook.propay.co.za/laravel/validation"
---
# Validation

Avoid using `|` as a separator for validation rules; always use array notation. Array notation makes it easier to apply custom rule classes to a field.

<code-group>

```php [PHP]
// GOOD
public function rules(): array
{
    return [
        'email' => ['required', 'email'],
    ];
}

// BAD
public function rules(): array
{
    return [
        'email' => 'required|email',
    ];
}
```

</code-group>

## Custom validation

All [custom validation](https://laravel.com/docs/12.x/validation#custom-validation-rules) rules must use snake_case and will need to be built using the Rules option in Laravel, to keep consistency across systems.

<code-group>

```php [PHP]
Validator::extend('is_null', fn ($attribute, $value, $parameters, $validator) => $value === null);
```

</code-group>

## API Validation

Make use of Laravel form requests to validate incoming requests — NO validation rules in the controllers or services. Single responsibility.


## Sitemap

See the full [sitemap](https://handbook.propay.co.za/sitemap.md) for all pages.
