--level used: 3When creating a validator instance via the validator() helper, the following error is thrown:
Call to an undefined method
Illuminate\Contracts\Validation\Factory|Illuminate\Contracts\Validation\Validator::setAttributeNames().
In code I set a custom attribute name based on the localization used for the application.
public function process(Request $request): RedirectResponse
{
$validator = validator($request->all(), [
'message' => 'required',
]);
$validationAttributeNames = [
'message' => trans('g.label.message'),
];
$validator->setAttributeNames($validationAttributeNames);
$validator->validate();
// Further method implementations
}
I hope you can help me out!
Kind Regards!
Hi,
Weird, this error shouldn't happen on level 3. I thought errors related to union types are started reporting on level 7.
Anyways, this is a feature request for a new extension for validator helper function.
For now you can use
/** @var \Illuminate\Contracts\Validation\Validator $validator */
$validator = validator($request->all(), [
'message' => 'required',
]);
// Rest of the code
to resolve it.
I'll try to implement the new extension later.
Most helpful comment
Hi,
Weird, this error shouldn't happen on level 3. I thought errors related to union types are started reporting on level 7.
Anyways, this is a feature request for a new extension for
validatorhelper function.For now you can use
to resolve it.
I'll try to implement the new extension later.