How to use "request unique" in the following situation

1

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

The two methods pass through the Request before entering into the bank, but the Request validates if the check is not present. It works perfectly for the new one, however when editing a check, Request passes again and ends up conflicting with the number itself.

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

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',

    ];
}
    
asked by anonymous 15.10.2018 / 18:06

1 answer

1

The solution was as follows

'conta' => "required|max:255|unique:tb_contas_bancarias,conta,{$this->id},id,deleted_at,NULL",

response was at this link: link

    
17.10.2018 / 14:07