Laravel 5 custom validator
As the official documentation doesn’t specify how exactly to create a custom
validation class.
1. Create custom validator class
You can create in any where as you like. For my example, I will create in
app/Libraries/CustomValidator.php
1 | namespace App\Libraries; |
2. Update to provider
Edit the file app/Providers/AppServiceProvider.php
1 | namespace App\Providers; |
3. Add the error message to language file
Edit resources/lang/en/validation.php and add this
1 | 'custom_rule' => 'The :attribute has custom error.', |
Test it
1 |
|
References: