Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Walter Felipe
submeta
Commits
2e1284dd
Commit
2e1284dd
authored
2 years ago
by
luisfrl
Browse files
Options
Download
Email Patches
Plain Diff
feat: criando rule para email unico
parent
e3963658
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/Http/Controllers/AdministradorController.php
+6
-6
app/Http/Controllers/AdministradorController.php
app/Http/Controllers/Auth/RegisterController.php
+3
-2
app/Http/Controllers/Auth/RegisterController.php
app/Rules/UniqueEmail.php
+41
-0
app/Rules/UniqueEmail.php
with
50 additions
and
8 deletions
+50
-8
app/Http/Controllers/AdministradorController.php
View file @
2e1284dd
...
...
@@ -38,7 +38,7 @@ use Illuminate\Validation\Rule;
use
PDF
;
use
DB
;
use
App\AreaTematica
;
use
App\Rules\UniqueEmail
;
class
AdministradorController
extends
Controller
{
...
...
@@ -531,7 +531,7 @@ class AdministradorController extends Controller
$validated
=
$request
->
validate
([
'name'
=>
[
'required'
,
'string'
,
'max:255'
],
'tipo'
=>
[
'required'
],
'email'
=>
[
'required'
,
'string'
,
'email'
,
'max:255'
,
'unique:users'
],
'email'
=>
[
'required'
,
'string'
,
'email'
,
'max:255'
,
new
UniqueEmail
(
$request
->
email
)
],
'instituicao'
=>
[
'required_if:instituicaoSelect,Outra'
,
'max:255'
],
'instituicaoSelect'
=>
[
'required_without:instituicao'
],
'senha'
=>
[
'required'
,
'min:8'
],
...
...
@@ -543,20 +543,20 @@ class AdministradorController extends Controller
$validated
=
$request
->
validate
([
'name'
=>
[
'required'
,
'string'
,
'max:255'
],
'tipo'
=>
[
'required'
],
'email'
=>
[
'required'
,
'string'
,
'email'
,
'max:255'
,
'unique:users'
],
'email'
=>
[
'required'
,
'string'
,
'email'
,
'max:255'
,
new
UniqueEmail
(
$request
->
email
)
],
'instituicao'
=>
[
'required_if:instituicaoSelect,Outra'
,
'max:255'
],
'instituicaoSelect'
=>
[
'required_without:instituicao'
],
'celular'
=>
[
'required'
,
'string'
,
'telefone'
],
'senha'
=>
[
'required'
,
'min:8'
],
'confirmar_senha'
=>
[
'required'
,
'min:8'
],
'cpf'
=>
[
'required'
,
'cpf'
,
'unique:users'
],
'cpf'
=>
[
'required'
,
'cpf'
,
new
UniqueEmail
(
$request
->
email
)
],
]);
}
else
{
$validated
=
$request
->
validate
([
'name'
=>
[
'required'
,
'string'
,
'max:255'
],
'email'
=>
[
'required'
,
'string'
,
'email'
,
'max:255'
,
'unique:users'
],
'email'
=>
[
'required'
,
'string'
,
'email'
,
'max:255'
,
new
UniqueEmail
(
$request
->
email
)
],
'tipo'
=>
[
'required'
],
'cpf'
=>
[
'required'
,
'cpf'
,
'unique:users'
],
'cpf'
=>
[
'required'
,
'cpf'
,
new
UniqueEmail
(
$request
->
email
)
],
'celular'
=>
[
'required'
,
'string'
,
'telefone'
],
'senha'
=>
[
'required'
,
'min:8'
],
'confirmar_senha'
=>
[
'required'
,
'min:8'
],
...
...
This diff is collapsed.
Click to expand it.
app/Http/Controllers/Auth/RegisterController.php
View file @
2e1284dd
...
...
@@ -15,6 +15,7 @@ use App\Proponente;
use
App\Endereco
;
use
App\Rules\UrlValidacao
;
use
App\Curso
;
use
App\Rules\UniqueEmail
;
class
RegisterController
extends
Controller
{
...
...
@@ -60,7 +61,7 @@ class RegisterController extends Controller
{
return
Validator
::
make
(
$data
,
[
'name'
=>
[
'required'
,
'string'
,
'max:255'
],
'email'
=>
[
'required'
,
'string'
,
'email'
,
'max:255'
,
'unique:users'
],
'email'
=>
[
'required'
,
'string'
,
'email'
,
'max:255'
,
new
UniqueEmail
(
$data
[
'email'
])
],
'password'
=>
[
'required'
,
'string'
,
'min:8'
,
'confirmed'
],
'cpf'
=>
[
'required'
,
'cpf'
,
'unique:users'
],
'rg'
=>
[
'required'
,
'unique:participantes'
],
...
...
@@ -76,7 +77,7 @@ class RegisterController extends Controller
return
Validator
::
make
(
$data
,
[
'name'
=>
[
'required'
,
'string'
,
'max:255'
],
'email'
=>
[
'required'
,
'string'
,
'email'
,
'max:255'
,
'unique:users'
],
'email'
=>
[
'required'
,
'string'
,
'email'
,
'max:255'
,
new
UniqueEmail
(
$data
[
'email'
])
],
'password'
=>
[
'required'
,
'string'
,
'min:8'
,
'confirmed'
],
'cpf'
=>
[
'required'
,
'cpf'
,
'unique:users'
],
'rg'
=>
[
'required'
,
'unique:participantes'
],
...
...
This diff is collapsed.
Click to expand it.
app/Rules/UniqueEmail.php
0 → 100644
View file @
2e1284dd
<?php
namespace
App\Rules
;
use
Illuminate\Contracts\Validation\Rule
;
use
Illuminate\Support\Facades\DB
;
class
UniqueEmail
implements
Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public
function
__construct
()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public
function
passes
(
$attribute
,
$value
)
{
return
empty
(
DB
::
table
(
"users"
)
->
where
(
"email"
,
'ilike'
,
$value
)
->
first
());
}
/**
* Get the validation error message.
*
* @return string
*/
public
function
message
()
{
return
'Email já está cadastrado'
;
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment