S
S
Sectorrbs2022-04-20 07:33:25
Laravel
Sectorrbs, 2022-04-20 07:33:25

Why do string validation and image type validation conflict in Laravel validation?

I prescribe this kind of check in request.
'img' => 'string|mimes:png',
The input "img" can be either a .png file or a regular string like "picture.png". Validation does not skip a line, it gives out: The img must be a file of type: png.
Help to understand this issue, perhaps there is still a correct way to write this type of check?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pLavrenov, 2022-04-20
@pLavrenov

Each rule is a function that returns false if it fails the test. They are performed in sequence. To solve the problem, you need to write your own rule that will check whether it fits or not.
Validation Rule

T
TheAndrey7, 2022-04-20
@TheAndrey7

The file upload field and the regular text field are not interchangeable. They work in a completely different way and must have a different name , and there the problem with the rules will be solved. Already in your controller logic, choose the value of one of the fields, depending on the filling.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question