在 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'));
}
这似乎是很多代码(+它不起作用),我无法找到这种情况的示例