You can override attribute names that default to the field name.
With a form request
attributes():
public function attributes()
{
return [
'this_is_my_field' => 'Custom Field'
];
}
4- :
$this->validate($request, $rules, $messages, $customAttributes);
Validator::make($data, $rules, $messages, $customAttributes);
Route::get('/', function () {
$data = [
'this_is_my_field' => null
];
$rules = [
'this_is_my_field' => 'required',
];
$messages = [
'required' => 'The message for :attribute is overwritten'
];
$customAttributes = [
'this_is_my_field' => 'Custom Field'
];
$validator = Validator::make($data, $rules, $messages, $customAttributes);
if ($validator->fails()) {
dd($validator->messages());
}
dd('Validation passed!');
});