Laravel profile update with e-mail unique:users -
i'm new in laravel. try make profile update page... works if try apply rule set email field unique:users have problem when user try update example name , don't want change email.
public function rules() { return [ 'name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', ]; }
i want restrict user use same e-mail else using... want ignore if same e-mail in user profile , don't want change that.
public function updatedata(updatedatarequest $request){
db::table('users') ->where('id', auth::user()->id) ->update(array('email' => $request->email, 'name' => $request->name)); return redirect('panel');
}
how right?
this exact situation used example in docs.
https://laravel.com/docs/5.2/validation#rule-unique
forcing unique rule ignore given id:
sometimes, may wish ignore given id during unique check. example, consider "update profile" screen includes user's name, e-mail address, , location. of course, want verify e-mail address unique. however, if user changes name field , not e-mail field, not want validation error thrown because user owner of e-mail address. want throw validation error if user provides e-mail address used different user. tell unique rule ignore user's id, may pass id third parameter:
'email' => 'unique:users,email_address,'.$user->id
if table uses primary key column name other id, may specify fourth parameter:
'email' => 'unique:users,email_address,'.$user->id.',user_id'
Comments
Post a Comment