How to use "request" in the following situation

Asked

Viewed 54 times

1

I have two methods in Controller that has the function of saving a new check and another that updates the check with edit.

The two methods go through Request before entering into the bank, but Request validates if the check is non-existent. Works perfect for the new, but when editing a check, Request passes again and ends up conflicting with the number itself.

How to prevent it from looking at the number that is being edited only and can rather be the same in this exception case.

Controller

public function atualizar(ChequeRequest $request) {
    $id = $request->input('id');
    $contaUpdate = Cheque::findOrFail($id);
    $input = $request->all();
    $contaUpdate->fill($input)->save();
    Session::put('success', "Cheque alterado com sucesso!");
    return redirect()->action($this->viewRetorno);
}

public function salvar(ChequeRequest $request) {

    Cheque::create($request->all());
    Session::put('success', "Cheque adicionado com sucesso!");
    return redirect()->action($this->viewRetorno);
}

Request Class

 public function rules() {

    return [
        'agencia' => 'required|max:255',
        'idBanco' => 'required|numeric',
        'conta' => 'required|max:255',
        'numero' => "required|unique:tb_cheques,numero,NULL,{$this->id},deleted_at,NULL",
        'data_cheque' => "required|date_format:Y-m-d",
        'valor' => 'required|numeric',
        'observacoes' => 'max:255',

    ];
}
  • Rafael, look at the documentation ( https://laravel.com/docs/5.7/validation#Rule-Unique )

  • But I can’t use this ignore there in my code without using the 5.7? to using the 5.0 Standard. it would be interesting if I could ignore as another Unique parameter.

1 answer

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.