C
C
chelkaz2017-05-15 18:01:21
Laravel
chelkaz, 2017-05-15 18:01:21

Laravel 5.4 Validator & Why does it filter randomly?

In the HTML form, the fields are:
category (Select), title (Input), text (TextArea) In the Validator
controller

'category' => 'required|exists:categories,code',
'title' => 'required|between:15,150',
'text' => 'required|between:30,5000',

And here's the paradox...
If all fields are empty, it returns all errors correctly.
If you fill in only the title and pass one character in it, then it returns all 4 errors correctly.
If you fill in the title and text ytsuken, THEN SKIPS! How is that?
If you fill in the title and text - qwerty, then it returns all errors. Which is right.
And the most interesting is if I catch errors in the controller:
if ($validator->fails()) {
dd($validator->messages());
}

That catches everything right! But I just do:
return back()->withErrors($validator)->withInput();

How the paradox in the view begins...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
chelkaz, 2017-05-16
@chelkaz

Outcome: Many here began to "yell" look at the documentation, etc. Apparently they write like this everywhere where the question is more complicated than 2 + 2.
Therefore, maybe someone will come across I tell. Tested with different session drivers. There was a Google Recaptcha on the village! (not connected for validation in the validator)
So, if there is a session driver - SESSION_DRIVER=cookie And fill in some of the fields incorrectly, and then click the recaptcha "I'm not a robot" and send, then if there are errors, it will redirect back, but with an empty $validator-> messages()
The most interesting thing is that recaptcha itself as a functional is not connected in the system!!! The process of pressing the button is important, apparently at this moment it changes the DOM in the browser and somehow affects it.
If you do not click it, then the validator works and redirects correctly!
But when I changed the driver to SESSION_DRIVER=database
That all earned without errors!
By trial, it turned out that recaptcha affects the session in the Chrome browser when SESSION_DRIVER=cookie
is set in the Laravel settings. If there is someone who will link all this in more detail, it will be great!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question