Skip to content

Commit 9933740

Browse files
Issue : #354
- Added unique email validation in user create scenario - Updated unique email validation logic, now it will check for email with trashed records as well
1 parent 192286f commit 9933740

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

app/Repositories/Backend/Access/User/UserRepository.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public function create($request)
9696
$permissions = $request->get('permissions');
9797
$user = $this->createUserStub($data);
9898

99+
$this->checkUserByEmail($data, $user);
100+
99101
DB::transaction(function () use ($user, $data, $roles, $permissions) {
100102
if ($user->save()) {
101103

@@ -322,17 +324,20 @@ public function mark($user, $status)
322324
* @param $input
323325
* @param $user
324326
*
327+
* @return null
325328
* @throws GeneralException
326329
*/
327-
protected function checkUserByEmail($input, $user)
330+
protected function checkUserByEmail($input, $user = null)
328331
{
329332
//Figure out if email is not the same
330-
if ($user->email != $input['email']) {
331-
//Check to see if email exists
332-
if ($this->query()->where('email', '=', $input['email'])->first()) {
333-
throw new GeneralException(trans('exceptions.backend.access.users.email_error'));
334-
}
333+
if ($user && $user->email === $input['email']) {
334+
return;
335335
}
336+
337+
//Check to see if email exists
338+
if ($this->query()->where('email', '=', $input['email'])->withTrashed()->exists()) {
339+
throw new GeneralException(trans('exceptions.backend.access.users.email_error'));
340+
}
336341
}
337342

338343
/**

0 commit comments

Comments
 (0)