Skip to content
Advertisement

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

JavaScript

ValidateArrayElementRule.php

JavaScript

ExamPaperQuestionsController.php

JavaScript

In my test file I have

JavaScript

ExamPaperQuestionStoreRequest.php

JavaScript

The test is failing

Expected status code 422 but received 201.

I can see the text “HERE” is logged but “there” is not. Why is my validation passes() function not being called?

Advertisement

Answer

Suppose if your request contain empty then it wont call custom validation. So you must add required filed to ensure request has key questions

JavaScript

Incase questions is optional and if entered then at least two or three item required then you can use required if validation.

By default laravel support min in array

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement