Check my answer (second solution) on how to do it
https://laracasts.com/discuss/channels/code-review/validation-rule-for-unique-on-2-fields
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi there I have two fields one for country code and one for phone number I want to make validation to make the both fields unique together.
public function rules()
{
return [
'countryCode' => ['required', 'between:2,4'],
'phone' => ['required', 'digits:9', 'unique:devices,phone],
];
}
I have two fields in the database one for country code, one for the phone number
I need the validation to check if the combination (country code with phone) is unique e.g +200102030 not the phone number only 0102030
I have done this in my app Where the combination between the first and the last name of an author must be unique.
'first_name' => 'required|unique:authors,first_name,' . null . ',id,last_name,'. $request->last_name
It should be quite easy for you to change the name of the fields to suit your needs.
Please or to participate in this conversation.