2015-02-10 24 views
0

嗨我試圖通過那裏的id那裏更新一個用戶在那裏配置文件部分。如果沒有驗證錯誤,這工作得很好,但是如果我刪除我拋出瞭如下錯誤的用戶名:Laravel存儲庫更新不允許序列化'Closure'

Serialization of 'Closure' is not allowed

相反,我本來期望的驗證錯誤消息的,任何人都可以指教一下這個意味着什麼我可以解決這個問題?我正在使用自定義存儲庫來處理數據庫交互。我的個人資料控制器具有這樣的功能:

public function updateProfileuser($id) 
    { 
     $updateprofileuser = $this->profile->findUserbyid($id); 

     if($updateprofileuser) 
     { 
     $updateprofileuser = $this->profile->updateProfile($id, Input::all()); 

      return Redirect::to('/profile')->with('success', 'Updated Profile'); 
     } elseif(!$updateprofileuser) 
       { 
        return Redirect::back()->withInput()->withErrors($this->profile->errors); 
       } 
    } 

而在我的回購協議updateProfile()函數是這樣:

public function updateProfile($id) { 

    $rules = array(
     'username' => 'required', 
     'email' => 'required' 
    ); 

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

     if($validator->fails()) { 
     $this->errors = \Session::flash('errors', $validator); 

     } else { 

      $user    = \User::find($id); 
      $user->firstname = \Input::get('firstname'); 
      $user->lastname  = \Input::get('lastname'); 
      $user->username  = \Input::get('username'); 
      $user->email  = \Input::get('email'); 
      $user->save(); 
     } 
} 

和我的錯誤,我的回購協議中的作用是如此:

public function errors() 
    { 
    return $this->errors; 
    } 

和我的回購界面

public function updateProfile($id); 

public function errors(); 

任何想法,我錯誤的傳遞錯誤信息?

回答

1

的問題是在這裏:

$this->errors = \Session::flash('errors', $validator); 

您試圖序列化$驗證對象到閃存會話,

所以只是把它改成這樣:

$this->errors = $validator; 

雖然我建議你折射你的代碼,我有點困惑於你想要完成的事情,所以這只是一個建議。

你updateProfileuser功能:

public function updateProfileuser($id) 
{ 
    $updateprofileuser = $this->profile->findUserbyid($id); 

    if($updateprofileuser) 
    { 

    $rules = array(
     'username' => 'required', 
     'email' => 'required' 
    ); 

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

    if($validator->fails()){ 
     return Redirect::back()->withInput()->withErrors($validator); 
    }else{ 
     $this->profile->updateProfile($id); 
     return Redirect::to('/profile')->with('success', 'Updated Profile'); 
    } 

    } else{ 
    //I don't know what you expect to pass here when $this->profile->findUserbyid($id) doesn't find anything 
    $this->profile->errors = 'Id not found'; 
    return Redirect::back()->withInput()->withErrors($this->profile->errors); 
    } 
} 

而且你updateProfile功能:

public function updateProfile($id) { 
    $user    = \User::find($id); 
    $user->firstname = \Input::get('firstname'); 
    $user->lastname  = \Input::get('lastname'); 
    $user->username  = \Input::get('username'); 
    $user->email  = \Input::get('email'); 
    $user->save(); 
} 
相關問題