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' 

http://four.laravel.com/docs/validation#rule-unique


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -