S
S
Sergey Zavialov2019-03-03 14:29:28
Laravel
Sergey Zavialov, 2019-03-03 14:29:28

How to see validation errors?

in the template before the form, the output of validation errors is registered

@if(count($errors) > 0)
    <div class="alert alert-danger">
      <ul>
        @foreach($errors->all() as $error)
          <li>{{ $error}}</li>
        @endforeach 
      </ul>
    </div>
  @endif

The validation condition is written.
The following is written in the controller
<?php
namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;

use App\Http\Requests\ContactRequest;

use App\Http\Controllers\Controller;

use Validator;

class ContactController extends Controller
{
    public function show(Request $request, $id=FALSE) {
    	
    	if($request->isMethod('post')) {

    $validator = Validator::make($request->all(),[
        'name'=>'required'
      ],$messages); 

    if($validator->fails()) {
        return redirect()->route('contact')->withErrors($validator)->withInput();
      }		
  }
  }
  }

But it stubbornly shows 0 errors for me, I specifically checked whether there are errors or not, and accordingly no errors are displayed. What could be the reason here?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
J
JhaoDa, 2019-03-03
@JhaoDa

" Displaying The Validation Errors ", first paragraph, last word.

A
Anton Shelestov, 2019-03-03
@ShelestovAnt

Why do it through Validator::make if it is possible through $request->validate(...), then you won't need to check with a redirect, it will do everything by itself.

R
Roman, 2019-03-03
@procode

I would
bb($validator);
I alternately inserted it in different places - I would test where exactly the plug is

L
Lieroes, 2019-03-04
@Lieroes

If I were you, I would install Debugbar , where you can check the validation, as well as access other useful metrics.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question