5
Good morning. Guys, I have a request created for user validation, but when I update a record it validates the Unique field I set in validation.. I tried to pass $this->id along so that it ignores, but without success.. someone has already gone through it.?
Laravel version: 8.0
Note: I am developing everything for API’s.
Controller code
public function update(UsuarioRequest $request, $id)
{
$usuario = Usuario::find($id);
if($usuario){
Usuario::find($id)->update($request->all());
return response()->json("Usuario atualizado com sucesso", 201);
}else{
return response()->json("Usuario nao encontrado", 200);
}
}
Request code
public function rules()
{
$rules = [
'nome' => 'required|max:100|min:2',
'sobrenome' => 'required|max:100|min:2',
'cpf' => 'required|unique:usuario',
'rg' => 'required|unique:usuario',
'data_nascimento' => 'required|date',
'rua' => 'required|max:300|min:2',
'bairro' => 'required|max:300|min:2',
'cidade_id' => 'integer',
'semestre_id' => 'integer',
'periodo_letivo_id' => 'integer',
'email' => 'required|max:200|email|unique:usuario',
'status' => 'required|integer',
'profissao_id' => 'integer',
'sexo_id' => 'integer',
'naturalidade_id' => 'integer',
'telefone1' => 'required|max:45',
'telefone2' => 'max:45',
'perfil_id' => 'integer',
'filial_id' => 'integer'
];
return $rules;
}
I don’t understand, I thought Ctrl+C Ctrl+V was simpler than an image...
– Edu Mendonça
Rafael, thank you very much. solved.
– MHPA
@Rafael Afonso, please avoid posting
imagens
code in your posts - questions and/or answers. To understand the real reasons read [Manual of how NOT to ask a question(https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-n%C3%83o-ask-questions).– Solkarped