I’ve been working on a Laravel API with validation. I’m sending this request to the server: On my development system, running windows/Apache/PHP 8.1, the POST requests return a JSON object containing validation errors. But my test system, running Linux/Apache/PHP 8.1, does not return a JSON response: Here is my code: api.php StoreClientRequest.php ClientAPIController.php Since it’s working on my localhost I
Tag: laravel-validation
How to show only one error message from Laravel request rules
I am using Laravel request to validate in my controller the requested data and here is my request file data I am facing two challanges first I am not able to return custom message using static function I am not able to send single message as we send in controller validation using errors()->first(). By defalut it is returning like that
How to validate integers and max float digits in one rule in laravel
Hey guys I need to validate something on my laravel application and I don’t know how. So if the user introduces 1234.55 it should allow it, because it have only 5 numbers, but if the user introduces 12345678.55 must reject! What I have until now. I tried to use digits_between, but when I use this, the validation doesn’t allow float
Custom validation not calling the passes() function
I am trying to make a validation that will check whether at least one item is provided in an array following the steps in Custom Validation Rules Routes.php ValidateArrayElementRule.php ExamPaperQuestionsController.php In my test file I have ExamPaperQuestionStoreRequest.php The test is failing Expected status code 422 but received 201. I can see the text “HERE” is logged but “there” is not.
FormRequest message in laravel 8 not show messages
In my laravel 8 app I am trying to create two files CreateUserRequest and updateUserRequest to use personalized validations. In the method rules I´m calling my model’s variable $createRules but when I send my form, this don´t send, don´t show messages, error… Nothing. I have attached CreateUserRequest, my model and controller’s store method: CreateUserRequest Model Controller’s store method In the
Validating non-required associative array with required fields
I want to validate that if my request contains a field of associative array type, that array needs to contain specific fields (but only if it’s present) Ie, array, if present, needs to contain foo: and is fine, but and is not. I’ve written this validator: But it doesn’t accept the first scenario. I’d like to avoid using ‘data.array.foo’ =>
How to use required_if on file array fields with an array for first argument?
I have an with an array of image_file (image_file[1], image_file[2]). They are input of type file. This images are required only if another array of fields (proposition_type) is defined on 2. For example : if proposition_type[1] == 2, image_file[1] has to be filled ; if proposition_type[2] == 1, image_file[2] has not to be filled. I have tried to use the
Laravel: How to use the ignore rule in Form Request Validation
Laravel has a ‘unique’ rule with an ‘except’ clause. From the validation documentation, it takes this form: My application has a ‘shop’ entity. When the user updates the shop’s profile, I have a Form Request, with a validation rule configured as follows: (The primary key on my shops table is id). The problem is that Laravel does not take any
Laravel Validation Rules If Value Exists in Another Field Array
I am working in Laravel 5.4 and I have a slightly specific validation rules need but I think this should be easily doable without having to extend the class. Just not sure how to make this work.. What I would like to do is to make the ‘music_instrument’ form field mandatory if program array contains ‘Music’. I found this thread
How to validate an input field if value is not null in Laravel
I am trying to create and update users with laravel 5.4 This is the validation added for create user. It works. On update the password field is not required. But validate the min:6 and confirmed rule if the password field is not null. Tried with sometimes.. but not working.. Answer try using nullable as a rule see https://laravel.com/docs/5.8/validation#a-note-on-optional-fields