Answer the question
In order to leave comments, you need to log in
How to validate for the uniqueness of two fields in a bundle in Laravel 5?
How to create a rule so that the fields tk_id and num_id do not repeat in a bundle, for example:
id: 1, tk_id: 1 and num_id: 1 - true
id: 2, tk_id: 2 and num_id: 1 - true
id: 3, tk_id: 1 and num_id:1 - false
Answer the question
In order to leave comments, you need to log in
Learn to use a search engine.
https://github.com/felixkiss/uniquewith-validator
https://laravel.com/docs/5.3/validation#rule-unique
use Illuminate\Validation\Rule;
public function rules()
{
$rules = [
'name_eng'=>'required|string',
'field1' => [
'required',
Rule::unique('table_name')->where(function ($query) {
$query->where('field2', $this->get('field2'));
})
],
];
return $rules;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question