Asked Aug 2nd, 2:23 AM 63 0 2
  • 63 0 2
0

Hỏi về validate trong laravel

Share
  • 63 0 2

Em có bảng bank (id, name, bank_number) em muốn validate unique theo 2 trường name, bank_number. không phải unique theo từng trường mà cả 2 cùng lúc

2 ANSWERS


Answered Aug 2nd, 2:37 AM
Accepted
+3

Bạn thử dùng Rule::unique :

[
   'name' => [ 
        'required', 
        Rule::unique('bank')->where(function ($query) use($request) {
              return $query->whereName($request->name)->whereBankNumber($request->bank_number); 
         }),
   ]
]
Share
Answered Aug 2nd, 5:48 AM
0

unique:bank ,name' . (($this->offsetExists(id') && $this->id) ? ",$this->id,id" : ',NULL,id') . ',bank_number,' . $this->bank_number

Share
Viblo
Let's register a Viblo Account to get more interesting posts.