ardent
ardent copied to clipboard
updateUniques() still making unique rules go through to save()
This is what my rules are in my model that is extending a package that extends Ardent:
public static $rules = array(
'email' => 'required|unique:users|email|max:100',
'password' => 'sometimes|required|confirmed',
'password_confirmation' => 'sometimes|required',
'fname' => 'required|max:64',
'lname' => 'required|max:64',
'address' => 'max:50',
'city' => 'max:50',
'state' => 'max:6',
'zip' => 'max:6',
'phone' => 'max:64'
);
Then I have my method:
/**
* Update user information
* @param columns Array of input
*
*/
public function updateUser( array $columns, $id = null )
{
if(is_null($id))
$id = \Auth::id();
$user = User::find($id, array('email', 'fname', 'lname', 'email', 'address', 'city', 'state', 'zip', 'phone'));
foreach( $columns as $column => $val )
{
$user->$column = $val;
}
if( $user->updateUniques() )
{
return true;
}
Session::set('error', $user->errors()->all());
return false;
}
But it's still saying email must be unique.. which makes no sense because updateUniques should ignore that shouldn't it?? In the uniqueExclusion method, it still spits this out:
string 'unique:users,email,,id' (length=22)
Which I would think that rule would get erased?
Well looks like you have to select the id when pulling a model object with updateUniques().. selecting the id with everything else I previously had did the trick. Might be good to note this.
@IntellectProductions I believe I am having the same problem. Can you elaborate on what you meant? It looks like in your code you already were selecting the id of the user...