From 80c9c956fc2d52b676b507169b241b4adf094712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20HEYD?= Date: Tue, 18 Apr 2017 17:38:12 +0200 Subject: [PATCH] Fix user registration when user is deleted --- src/Controllers/Auth/RegisterController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Controllers/Auth/RegisterController.php b/src/Controllers/Auth/RegisterController.php index 487d7a8a..c8ad8dda 100755 --- a/src/Controllers/Auth/RegisterController.php +++ b/src/Controllers/Auth/RegisterController.php @@ -59,7 +59,7 @@ protected function validator(array $data) return Validator::make($data, [ 'last_name' => 'required|max:255', 'first_name' => 'required|max:255', - 'email' => 'required|email|max:255|unique:users', + 'email' => 'required|email|max:255|unique:users,email,NULL,id,deleted_at,NULL', 'password' => 'required|min:6|confirmed', ]); } @@ -85,7 +85,7 @@ protected function create(array $data) $userModel = config('auth.providers.users.model'); $roleModel = config('laratrust.role'); - $user = $userModel::create([ + $user = $userModel::withTrashed()->updateOrCreate(['email' => $data['email']], [ 'active' => true, 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], @@ -98,8 +98,9 @@ protected function create(array $data) $admin = $roleModel::whereName('admin')->first(); $user->attachRole($admin); } else { + $user->restore(); $role = $roleModel::whereName(config('boilerplate.auth.register_role'))->first(); - $user->attachRole($role); + $user->roles()->sync([$role->id]); } return $user;