I'm trying to pass custom attributes as the fourth argument to the Validator. But, I don't want to add any custom messages. In order to do that, I need to skip the messages argument.
$validator = Validator::make($request->all(),[
'firmType' => 'required',
'firmName' => 'required|max:255',
'firmCode' => 'required'
],$message,[
'firmType' => 'Firm Type',
'firmName' => 'Firm Name',
'firmCode' => 'Firm Code'
]);
I need to skip to provide $message
array as I don't have any custom messages. Appreciate it if anyone could help with this.
CodePudding user response:
I personally think this is one of the limitations of using Validator::make(..).
I would suggest you make a seperate Form Request (https://laravel.com/docs/8.x/validation#creating-form-requests) where you supply rules and attributes as methods.
public function rules()
{
return [
'firmType' => 'required',
'firmName' => 'required|max:255',
'firmCode' => 'required'
];
}
public function attributes()
{
return [
'firmType' => 'Firm Type',
'firmName' => 'Firm Name',
'firmCode' => 'Firm Code'
];
}
CodePudding user response:
The below is the idea that I used to solve. Need to Pass an empty array for $message
argument
$validator = Validator::make($request->all(),[
'firmType' => 'required',
'firmName' => 'required|max:255',
'firmCode' => 'required'
],[],[
'firmType' => 'Firm Type',
'firmName' => 'Firm Name',
'firmCode' => 'Firm Code'
]);