php - Laravel 4 Validation -
i use following rules validation on creating new user:
protected $rules= [ 'name' => 'required', 'email' => [ 'required', 'unique:user', 'email' ] ];
when updating existing user use same ruleset shown above don't want validation error if user didn't change email @ all.
i resolve using following:
if (!user::changed('email')) { unset($user->email); }
it feels dirty workaround me wondering if there better alternatives.
also note changed
method wrote myself. know if there native laravel 4 method checking whether model property has changed?
thanks!
the unique validation rule allows ignore given id, in case id of data set updating.
'email' => 'unique:users,email_address,10'
Comments
Post a Comment