Larvel 5.2 error checking - bag error empty

I have a new site running Laravel 5.2 ( Laravel Framework version 5.2.39). NOTE: the routes file does NOT use a middleware group that is no longer needed and may cause this problem.

I have a simple method check ContactController store:

    $this->validate($request, [
        'ContactFirst' => 'required|max:25',
        'ContactLast' => 'required|max:25',
        'ContactRole' => 'required|max:25',
        'ContactEmail' => 'email|max:255',
        'ContactPhone' => 'max:255',
    ]);

When I intentionally refuse to check, the site is redirected back to the form, but the error bag is empty, so error information is not provided.

In the form view ( resources/contacts/new.blade.php), I put the following code from the documents and dump:

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

The page (as I said) redirects back to the form and the inputs are populated. But it is $errorsempty and messages are not printed:

object(Illuminate\Support\ViewErrorBag)[285]
protected 'bags' => 
array (size=0)
  empty
+4
3

, Homestead. , ​​.

+3

, , , , .

$validator->fails().

:

$validator = Validator::make($request->all(), [
    'ContactFirst' => 'required|max:25',
    'ContactLast' => 'required|max:25',
    'ContactRole' => 'required|max:25',
    'ContactEmail' => 'email|max:255',
    'ContactPhone' => 'max:255',
]);

if ($validator->fails()) {
    return redirect()->back()->withErrors($validator)->withInput();
}




ContactFormRequest, Request store ( : http://joxi.ru/eAO55BF4glwRmo):

<?php namespace App\Http\Requests;   

class ContactFormRequest extends Request {

    public function rules() {
        return [
            'ContactFirst' => 'required|max:25',
            'ContactLast' => 'required|max:25',
            'ContactRole' => 'required|max:25',
            'ContactEmail' => 'email|max:255',
            'ContactPhone' => 'max:255',
        ];
    }
}

store :

public function store(ContactFormRequest $request) {
    // here write code as if validation is valid
}

- , :

<?php var_dump(get_defined_vars()) ?>

{{var_dump($errors)}}

+3

. .

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

All Articles