bitfumes / laravel-multiauth

Multi Auth and admin auth in Laravel Project
MIT License
470 stars 105 forks source link

Fix PostgreSQL bug when creating new admins #135

Closed davecardwell closed 3 years ago

davecardwell commented 3 years ago

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

davecardwell commented 3 years ago

The Travis CI build is failing due to reasons unrelated to this pull request (cc @sarthaksavvy)

sarthaksavvy commented 3 years ago

Amazing, thanku for this contribution

tayeb-khan commented 2 years ago

you can just do it with using Rule class:

use Illuminate\Validation\Rule;

'required|'.Rule::unique('admins','email')->ignore(request('admin.id')),