0
Speak guys, I’m trying to learn Laravel and I’m currently caught in a seemingly simple thing, is the following.
I created a very simple system with login and other things, and I’m trying to implement the editing of the logged-in user data, I made the validations and defined that the email is.
<?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 record of some user, for not having changed the email of the same one is returned me the error, how can I make so that the validation of the email opens an exception for the user of that ID?
While I’m at it, I was wondering if this form of validation is indicated, correct, safe, efficient and things like that, you would have another way to recommend me?
But I do this, value="{{Auth::user()->email}}"> the problem is that the email that is in the user can theoretically not be saved in the database because it already exists, what I want to do is make an exception for a certain ID
– user74838
Got it, good you got it fixed :)
– teliz