1
I created a request with the command:
php Artisan make:request Nameserver
And in the controller I’m calling him so:
public function nomeDaFuncao(NomedoRequest $request)
{
}
Only I need to use this request in two situations, both when creating some data, and when editing, but one of these fields I need to be unique in the database. In Laravel has the validation Unique that allows me to say that that data needs to be unique, only if I try to pass the same data at the time of editing, it presents error speaking q is equal.
I found this feature
Rule::Unique('table')->ignore($email)
But I don’t know how to pass this $email variable to the request I created and even passing it, it will only work for one situation, or edit, or create. Function of the request:
public function rules()
{
return [
'name' => 'required|max:255',
'cpf' => 'required',
'phone' => 'required',
'birthdate' => 'required',
'sex' => 'required',
'email' => ['required', Rule::unique('users')->ignore($variavel)],
];
}