Question

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'));
}
Was it helpful?

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top