I'm trying to validate a form, where there are two mandatory columns whose combination must be unique in the table. Validator should also ignore the case of the input.
$data = request()->validate([
'dc_name' => 'required',
'dc_code' => ['required',
Rule::unique('dcs')->where(function ($query) use ($request) {
$query->where(DB::raw('lower(dc_name)'), strtolower($request->dc_name));
})
]
]);
Combination of dc_name and dc_code should not be repeated in the dcs table. The given code works with dc_code. But I don't want to repeat same thing for dc_name. Is there any simpler way to do this?