2017-04-21 181 views
0

把()當我試圖通過驗證返回錯誤象下面這樣:調用未定義的方法照亮的 Support MessageBag ::在Laravel 5.3

return Redirect::back()->withErrors($validator)->withInput();

它給我這個錯誤:

Call to undefined method Illuminate\Support\MessageBag::put()

其是: vendor\laravel\framework\src\Illuminate\Http\RedirectResponse.php line 133

的代碼是:

/** 
* Flash a container of errors to the session. 
* 
* @param \Illuminate\Contracts\Support\MessageProvider|array|string $provider 
* @param string $key 
* @return $this 
*/ 
public function withErrors($provider, $key = 'default') 
{ 
    $value = $this->parseErrors($provider); 

    $this->session->flash(
     'errors', $this->session->get('errors', new ViewErrorBag)->put($key, $value) 
    ); 

    return $this; 
} 

當你看到它應該使用put方法從ViewErrorBag不MessageBag!

任何幫助,將不勝感激...

回答

0

get('errors', new ViewErrorBag)將返回一個ViewErrorBagerrors關鍵並不在會話中。在這種情況下,會話中確實存在errors,它似乎是MessageBag的實例。所以,get('errors', new ViewErrorBag)返回MessageBag,然後嘗試打電話給put(),這給你你的錯誤。

您需要在代碼中找到您在errors會話密鑰中存儲MessageBag的位置,並更改該密鑰。

0

我覺得像你應該更新你的代碼:

return redirect()->back() 
      ->withInput() 
      ->withErrors($validator); 

OR 你需要更新你的作曲家:

composer dumpauto 
相關問題