Search code examples
phplaravel-4ardent

Laravel Ardent not saving model when using updateUniques()


I'm doing user editing facility for my admin panel. I'm using updateUniques() in my code, as recommended by Ardent when having 'unique' rules in the model.

When I do it, it passes with no problem, but model hasn't changed.

My code:

$user = User::findOrFail($id);

if ($user->exists)
{
    $user::$rules['password'] = (Input::get('password')) ? 'required|confirmed' : '';
    $user::$rules['password_confirmation'] = (Input::get('password')) ? 'required' : '';
}

if ($user->updateUniques())
{
    Session::flash('successes', array_merge((array) Session::get('successes'), ['Pomyślnie zmieniono użytkownika']));
    return Redirect::route('users.show', ['users'   =>  $user->id]);
}
else
{
    return Redirect::route('users.edit', ['users'   =>  $user->id])
    ->withErrors($user->errors())
    ->withInput(Input::except('password'));
}

Solution

  • When debugging it, I noticed that it doesn't hydrate the model with new data. After bit of googling I came up with a solution.

    I just needed to add following to my model:

    public $forceEntityHydrationFromInput = true;
    public $autoPurgeRedundantAttributes = true;