Answer the question
In order to leave comments, you need to log in
Why is laravel validator not showing errors?
I am studying laravel version 5.2 courses, I myself have laravel 7.x , I encountered such a problem that my validator works both when writing a check in both the old version and the new one, but the number of errors is constantly 0, and therefore does not display them on the screen, and does not save the data already entered in the session. Routes are correct, startsession and ShareErrorsFromSession are connected to Kernel in protected $middleware . here is the controller code with validator method
public function show(Request $request, $id = false)
{
if($request->isMethod('post')){
$rules = [
'name'=> 'required|max:10',
'email'=> 'required|email'
];
$this->validate($request,$rules);
dump($request->all());
}
return view('default.contact',['title' => 'Contacts']);
}
<p>{{count($errors)}}</p>
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
Answer the question
In order to leave comments, you need to log in
I solved the problem by disabling in $middleware such things as \Illuminate\Session\Middleware\StartSession::class,
and \Illuminate\View\Middleware\ShareErrorsFromSession::class, since they are already present in $middlewareGroups, due to the fact that I have and the teacher has different versions of Laravel, we have routes in different files, and since by default web.php (as I understand it at least) uses resources from the web group in the Kernel, the resources that duplicate them in $middleware created such a nuisance for me .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question