Reputation: 798
I am facing a problem with required_if that, when i need to validate if type_id = 3 external_id should be required.
$validator = Validator::make($request->all(), [
'memberID'=> 'required',
'external_id'=>'required_if:type_id,3'
]);
error message will be
The External id field is required when type id is 3.
validation working fine. But instead of type id is 3 i need to display a description. like below shown.
The External id field is required when type is category.
how to do that?
Upvotes: 0
Views: 150
Reputation: 3065
You can do that by create a custom validation message,
$customMessages = [
'required_if' => 'The :attribute field is required when type is category'
];
$validator = Validator::make($request->all(), [
'memberID'=> 'required',
'external_id'=>'required_if:type_id,3'
], $customMessages);
Upvotes: 2