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

4
  • Yes. What you did should work. Are there any errors you're getting or unexpected behaviour? Commented Apr 28, 2018 at 18:50
  • Possible duplicate of How add Custom Validation Rules when using Form Request Validation in Laravel 5 Commented Apr 28, 2018 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], ] Commented Apr 28, 2018 at 19:14
  • Add your custom rule to the question. (App\Rules\Uppercase) Commented Apr 28, 2018 at 21:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.