Is there a way to build a validation in Laravel which checks if two columns together are unique in a table?
So for example if there is [(A, B)] in my table, then the input (A, A) or (B, B) should pass the validation but (A, B) again have to fail.
For example like this:
DB::table('mytable')
->where([
['col1', $item->col1],
['col2', $item->col2]
])
->exists();
But I want to do it within a validation, so something simular to this:
public function validate() {
return Validator::make($this->attributes, [
'col1|col2' => 'unique:mytable',
//....
])->errors();
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire