laravel unique validation on multiple columns
snippet in php

Laravel unique validation on multiple columns

user7769

$messages = [
    'data.ip.unique' => 'Given ip and hostname are not unique',
];

Validator::make($data, [
    'data.ip' => [
        'required',
        Rule::unique('servers')->where(function ($query) use($ip,$hostname) {
            return $query->where('ip', $ip)
            ->where('hostname', $hostname);
        }),
    ],
],
$messages
);

Laravel unique validation on multiple columns

user195

[
     'column_1' => 'required|unique:TableName,column_1,' . $this->id . ',id,colum_2,' . $this->column_2
]

laravel unique multiple columns

user8758

$table->unique(['mytext', 'user_id']);

laravel unique validation on multiple columns

user1393

'mobile_no' 
  => 'unique:users,mobile_no,NULL,id,country_id,'.request('country_id');