在laravel/ardent中,编辑带有密码的用户模型的预期方式是什么?我的问题是,在用户输入正确验证之前,我不想从数据库加载实际的用户模型。当我将密码字段留空时,验证显然会失败,因为密码是必需的。这是我的当前后编辑操作:
public function postEdit($id)
{
// ardent autohydrates this model
$newUser = new User;
// validation fails
if(!$newUser->validate())
return Redirect::action('UsersController@getEdit', $id)
->with('error', Lang::get('Bitte Eingabe überprüfen'))
->withErrors($newUser->errors())
->withInput(Input::except('password'));
// load model from db
$exUser = User::find($id);
if(!$exUser->exists)
return Response::make('No such user', 500);
// save model, ardent autohydrates again?
if($exUser->save())
return Redirect::action('UsersController@getShow', $id)
->with('success', Lang::get('Änderungen gespeichert'));
else
return Redirect::action('UsersController@getEdit', $id)
->with('error', Lang::get('Bitte Eingabe überprüfen'))
->withErrors($newUser->errors())
->withInput(Input::except('password'));
}
这段代码似乎很长(而且还不能正常工作),我无法找到一个适用于这种情况的示例。