I have some hard times with Laravel Rules (importing csv file). I'm trying to use the Rule::unique function but when another field is not empty, for example:
public function rules(): array
{
return [
'code' => ['required', 'string', Rule::unique('product_gift_cards', 'code')],
'pin' => ['nullable'],
'sequence_number' => ['nullable']
];
}
So this code, should be unique only when sequence_number is not filled. When sequence_number is filled with something, the code should not be unique. I have deleted the unique index in the database, so it will work if I write is as needed, any suggestions?