laravel5.2错误未显示在刀片​​

时间:2017-04-01 04:44:52

标签: laravel

我正在尝试解决这个有线问题几个小时,但仍然会在模板中显示错误消息。 我已确保Web中间件(包含StartSession和ShareErrorsFromSession)包含在我的所有路径中。

Route::group(['namespace'=>'admin','prefix'=>'admin','middleware'=>['web']],function (){
Route::get('index','AdminController@index');
Route::get('addCase','CaseController@create');
Route::any('upload','AdminController@upload');
Route::resource('case', 'CaseController');

});

    public function store(Request $resquest)
{
    //
    $validator = Validator::make($resquest->all(), [
        'title' => 'required',
    ]);
    if($validator->passes()){

    }else{
        return back()->withErrors($validator);
    }

}


   <form method="post" class="form-horizontal" action="{{action('admin\CaseController@store')}}">
            {{ csrf_field() }}
            @if (count($errors) > 0)
                <div class="alert alert-danger">
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif
                <button>submit</button>
        </form>

请帮忙!

验证工作正常,但错误消失了

1 个答案:

答案 0 :(得分:0)

请试试这个

在控制器中

 $validator = Validator::make($request->all(),[
    'title' => 'required'});
  if($validator->fails()) {
        return Redirect::back()->withErrors($validator);
  }

在视图页面

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