Skip to content

Commit 24c1632

Browse files
authored
Fix PostgreSQL bug when creating new admins (#135)
* Fix PostgreSQL bug when creating new admins When creating a new admin the value of `request('admin.id')` is `NULL`, which means the email validation rule becomes `"required|email|max:255|unique:admins,email,"`. This results in the SQL `select count(*) as aggregate from "admins" where "email" = 'test@example.com' and "id" <> ''`, which causes an exception in PostgreSQL: `SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: ""`. This change first checks that `request('admin.id')` is not `NULL` before adding it to the email uniqueness check. Fixes #86 and fixes #114 * Fix linting issues
1 parent 4642010 commit 24c1632

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Http/Requests/AdminRequest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ public function authorize()
2525
*/
2626
public function rules()
2727
{
28-
$admin_id = request('admin.id');
28+
$email_rule = 'required|email|max:255|unique:admins,email';
29+
$admin_id = request('admin.id');
30+
if (!is_null($admin_id)) {
31+
$email_rule .= ",{$admin_id}";
32+
}
33+
2934
$rules = [
3035
'name' => 'required|max:255',
31-
'email' => "required|email|max:255|unique:admins,email,{$admin_id}",
36+
'email' => $email_rule,
3237
'password' => 'required|min:8|confirmed',
3338
'role_id' => 'required',
3439
];

0 commit comments

Comments
 (0)