The Laravel MessageBag error array is empty, but with content, if I kill the script

I am trying to return errors to my view, this is part of my TestcategoryController controller

    $rules =array(
        'name' => 'required'
    );
    $validator = Validator::make(Input::all(), $rules);
    //process
    if($validator->fails()){
        return Redirect::to('testcategory/create')->withErrors($validator);
    }

In the view testcategory/create, if I try to output errors, for example

        @if($errors->any())         
            {{ $errors->first('name') }}
        @endif

I get nothing. But if I {{dd($errors)}}, I get

      object(Illuminate\Support\ViewErrorBag)#91 (1) { ["bags":protected]=> array(1) { 
      ["default"]=> object(Illuminate\Support\MessageBag)#92 (2) 
      { ["messages":protected]=>   array(1) 
      { ["name"]=> array(1) { [0]=> string(27) "The name field is required." } }  
      ["format":protected]=> string(8) ":message" } } }

The only way to get errors is to kill the script. What am I doing wrong?

+1
source share
3 answers

, , $errors - - , . - . , $errors subview, .

+3

, , $errors $session .

: http://laravel.io/forum/03-28-2016-errors-variable-empty-after-failed-validation

, . : \Http\Kernel.php \Illuminate\Session\Middleware\StartSession::class, $middlewareGroups $middleware

enter image description here

enter image description here

+3

You need to use it as follows:

{{ $errors->getBag('default')->first('name') }}
0
source

All Articles