Talk to people, I'm trying to learn Laravel and I'm currently caught up in something apparently simple, it's the following.
I created a very simple system with login and other things, and I'm trying to implement editing the data of the logged in user, I made the validations and I defined the email as unique.
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UsersRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'type' => 'required|max:1'
];
}
public function messages(){
return [
'required' => 'O campo ":attribute" é obrigatório!',
'numeric' => 'O campo ":attribute" deve ser um número!',
'min' => 'O campo ":attribute" deve ter no mínimo :min caracteres!',
'max' => 'O campo ":attribute" deve ter no maximo :max caracteres!',
'type.required' => 'O campo "tipo" é obrigatório!',
'unique' => 'Este ":attribute" não se encontra disponivel no momento!'
];
}
}
So far so good, the validation works correctly, however, when I try to update the registry of some user, for not having changed the email of the same is returned the error, how can I make the unique validation of the email open an exception for the user of that ID?
I would like to know if this form of validation is indicated, correct, safe, efficient and the like, would you have another way to recommend me?