Composite unique field validation is provided out-of-the-box in 5.0+. I can't speak for earlier versions.
You can essentially specify a where clause for when your unique validation rule applies. E.g.
'term' => 'unique:terms,term,NULL,id,taxonomy,category'
This rule says that term
should be unique on the terms
table but only where the taxonomy
is equal to "category".
For example, it will prevent a "news" category being duplicated but I can still have a "news" tag.
I don't know your schema but in your case it'd be something like this:
$user_id = Request::get('user_id', $default);
$service_id = Request::get('service_id', $default);
// or another way of specifying the accompanying service/user ID for the where clauses
$rules = [
'user_id' => 'unique:service_details,user_id,NULL,id,service_id,' . $service_id;
'service_id' => 'unique:service_details,service_id,NULL,id,user_id,' . $user_id;
];
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…