AhmedNaser
3 weeks ago
203
8
Laravel

Laravel unique validation rule

Posted 3 weeks ago by AhmedNaser

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

Please sign in or create an account to participate in this conversation.