0

Is there a way to use the Custom Validation Rules https://laravel.com/docs/5.5/validation#custom-validation-rules

when using the Form Request?

I do not see it anywhere in the docs, and only similar questions on the web with no answer.

Example:

php artisan make:rule Uppercase

CustomRequest.php

use App\Rules\Uppercase;

protected $rules = [

      'Names' => ['required','string', new Uppercase],
]

UserController.php

public funcion store(CustomRequest $Request)
{

}

Any ideas anyone?

message Constant expression contains invalid operations exception Symfony\Component\Debug\Exception\FatalErrorException file C:\xampp\htdocs\jireh\app\Http\Requests\CustomRequest.php line: 22

  • Yes. What you did should work. Are there any errors you're getting or unexpected behaviour? – DevK Apr 28 '18 at 18:50
  • Possible duplicate of [How add Custom Validation Rules when using Form Request Validation in Laravel 5](https://stackoverflow.com/questions/28793716/how-add-custom-validation-rules-when-using-form-request-validation-in-laravel-5) – Mahdi Younesi Apr 28 '18 at 18:54
  • @MahdiYounesi is not the same This works for laravel 5.4, so I want to do php artisan make: rule UpperCase and enter in the array $ rules [ 'Names' => ['required', 'string', new Uppercase], ] – Raul David Apr 28 '18 at 19:14
  • Add your custom rule to the question. (App\Rules\Uppercase) – iamab.in Apr 28 '18 at 21:33

0 Answers0