2014-07-21 44 views
0

爲什麼超時我的頁面isset的加載沒有正確加載,它仍然向頁面顯示一個像這樣的數組。 []?Laravel Isset錯誤顯示[]

查看

@if(isset($errors)) 
{{$errors}} 
@endif 

控制器

$data = Input::all(); 

if($errors = $this->deliveryReport->isInvalid($data)) 
{ 
    return Redirect::back()->withInput()->withErrors($errors); 
} 

回答

3

這是最常見的使用聚光介紹:

@if($collection->isEmpty()) 
    <h2>No items were found</h2> 
@else 
    <h2>The following {{$collection->count()}} items were found</h2> 
    @foreach($collection as $c) 
     {{ $c->someAttribute }} 
    @endforeach 
@endif 

現在專門爲$errors

@if($errors->any()) 
    <div id="error-box"> 
     @foreach ($errors->all() as $error) 
      <div>{{ $error }}</div> 
     @endforeach 
    </div> 
@endif 

記住正確$errors到您的視圖通過驗證已完成其工作之後。所以在你的控制器中:

$rules = [...]; 

$v = Validator::make(Input::all(), $rules); 

if($v->fails()) 
{ 
    return Redirect::back()->withInput()->withErrors($v); 
} 

... 
1

withError()使它的MessageBag例如,你可以使用的方法就可以了:

@foreach($errors->all() as $error) 
    {{ $error }} 
@endforeach 

或看到docs