I have a senario, I have One field and I want to validate it on some condition like, If request has check field then apply unique validation on another table and if not present apply the same unique validation rule on the another table.
if ($request->input('check')) {
$request->validate([
'field' => [
Rule::unique('one_table', 'one_column')
],
]);
} else {
$request->validate([
'field' => [
Rule::unique('another_table', 'another_column')
],
]);
}
check and field are supposed request variables.
I don't know how to combine these condition into one condition.
CodePudding user response:
For this, you can use short condition :
$request->validate([
'field' => [
($request->input('check')? Rule::unique('one_table', 'one_column'):Rule::unique('another_table', 'another_column'))
],
]);