2016-01-13 79 views
2

這是不可能顯示在視圖中Laravel 5.2 - 沒有顯示錯誤

這裏的錯誤是我的控制器:

public function create(){ 
     return view('articles.create'); 
    } 

public function store(Request $request){ 
$this->validate($request, [ 
      'title' => 'required|max:5', 
      'content' => 'required', 
     ]); 
} 

這是我的看法create.blade.php:

 @if (count($errors) > 0) 
     <!-- Form Error List --> 
      <div class="alert alert-danger"> 
       <strong>Whoops!</strong> Something went wrong!.<br><br> 
       <ul> 
        @foreach ($errors->all() as $error) 
         <li>{{ $error }}</li> 
        @endforeach 
       </ul> 
      </div> 
     @endif 

內核.php ShareErrorsFromSession already there

protected $middlewareGroups = [ 
     'web' => [ 
      \App\Http\Middleware\EncryptCookies::class, 
      \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 
      \Illuminate\Session\Middleware\StartSession::class, 
      \Illuminate\View\Middleware\ShareErrorsFromSession::class, 
      \App\Http\Middleware\VerifyCsrfToken::class, 
     ], 

這裏是route.php 我已添加的路線網絡

Route::group(['middleware' => ['web']], function() { 
    Route::get('articles/create', '[email protected]'); // Display a form to create an article... 
}); 
Route::get('articles', '[email protected]'); // Display all articles... 
Route::post('articles', '[email protected]'); // Store a new article... 
Route::get('articles/{id}', '[email protected]'); 
+0

爲什麼你不把所有東西放到網絡中間件組中? –

+0

太棒了!你是對的。現在正在工作 – Lili

回答

0

你可以嘗試這樣的事情。

$data = array(); 
      $messages=array(
       'required' => "You can't leave this empty", 
      ); 
      $datavalidate = array(
       'name'  => $request->name, 
      ); 
      $rules = array(
       'name'    => 'required', 
      ); 

      $validator = Validator::make($datavalidate,$rules,$messages); 
      if($validator->fails()){ 
       return Redirect::back()->withErrors($validator); 
      } 

現在打印在視圖文件上。

{!! dd($errors) !!}