2016-08-05 29 views
0

我用withErrors()通過模板刀片驗證消息:爲什麼不能在Laravel中使用錯誤?

if ($validator->fails()) { 
      dd($validator); // Gives me filled array with messages 
      return Redirect::back() 
       ->withErrors($validator) 
       ->withInput(); 

在模板中,我有:

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

我想在模板調用堆棧問題刀片,或在功能上withErrors

如果withErrors使用會話,也許這是問題之一。

此外,這是我的電話驗證:

$validator = Validator::make($request->all(), [ 
      "name" => 'required|string|min:10', 
      "text" => 'required|string|min:10', 
     ]); 
+0

鑑於頁面是什麼DD的輸出($錯誤) –

+0

'ViewErrorBag {#255▼ #包:[] }' – Dev

+0

請嘗試dd($ errors-> toArray()) –

回答

1

嘗試有鑑於此:

@if(Session::has('error')) 
    {{ Session::get('error') }} 
@endif 
+0

沒有結果,再次爲空 – Dev

相關問題