0

Hi I need help in countering duplicate entries in laravel. Currently I am using the default laravel validator and I would like to make an alert stating if the username, email and phone number had already been registered. Thank you in advance.

protected function validator(array $data) { return Validator::make($data, [ 'name' => ['required', 'string', 'max:255'], 'username' => ['required', 'string', 'max:10', 'unique:users,username'], 'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email'], 'phone_number' => ['nullable', 'string', 'email', 'unique:users,phone_number'], 'password' => ['required', 'string', 'min:8', 'confirmed'], ]); } /** * Create a new user instance after a valid registration. * * @param array $data * @return \App\User */ protected function create(array $data) { return User::create([ 'name' => $data['name'], 'username' => $data['username'], 'email' => $data['email'], 'password' => Hash::make($data['password']), 'user_role' => 'user', 'has_agreed' => 1 ]); } 
5
  • Whats the actual problem here ? Commented Jul 6, 2020 at 6:04
  • Hi! When the entry has a duplicate it doesn't show any error or alert but instead simply removes the duplicated entries in the registration form. What I would like to happen is to let the user who plans to register know what happened why the registration didn't push through. Commented Jul 6, 2020 at 6:16
  • Already found the answer here stackoverflow.com/questions/49998255/… I am now closing this thread. Thank you Commented Jul 6, 2020 at 6:26
  • For the answer refer here stackoverflow.com/questions/49998255/… Commented Jul 6, 2020 at 6:27
  • Glad to hear that. Commented Jul 6, 2020 at 6:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.