Skip to content

Commit

Permalink
Fix user registration when user is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienheyd committed Apr 18, 2017
1 parent 0ab4c9c commit 80c9c95
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
}
Expand All @@ -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'],
Expand All @@ -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;
Expand Down

0 comments on commit 80c9c95

Please sign in to comment.