K
K
Kristina87872020-08-10 13:51:09
Laravel
Kristina8787, 2020-08-10 13:51:09

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']);
    }

and here in the template
<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

the method validates, I think so, because the dump works when the melons are entered correctly, and when not, it does not work, but none of them displays errors and does not save the already entered data in the session. What's wrong here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kristina8787, 2020-08-10
@Kristina8787

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 question

Ask a Question

731 491 924 answers to any question