Я использую laravel 5.8 и включил проверку. php на своем ресурсе / lang / xx / folder.
В своем контроллере я использую этот код для проверки полей:
$validator = Validator::make($request->all(), [
'lastname' => 'required',
'firstname' => 'required',
'gender' => 'required',
'birthplace_id' => 'required',
'birthdate' => 'required',
'fiscal_code' => 'required|unique:customers,fiscal_code,NULL,id,deleted_at,NULL',
]);
Мне не нужно возвращать $ validator, но мне нужно, в той же функции, распечатать ошибки. Я написал этот код:
if ($validator->fails()) {
\Log::info(json_encode($validator));
}
И я получил это:
{
"customMessages": [],
"fallbackMessages": [],
"customAttributes": [],
"customValues": [],
"extensions": [],
"replacers": []
}
это содержание моей проверки. php файл:
return [
/*
|--------------------------------------------------------------------------
| Validation Language Lines
|--------------------------------------------------------------------------
|
| The following language lines contain the default error messages used by
| the validator class. Some of these rules have multiple versions such
| as the size rules. Feel free to tweak each of these messages here.
|
*/
'required' => 'The :attribute field is required.',
'unique' => 'Il :attribute è già stato utilizzato.',
/*
|--------------------------------------------------------------------------
| Custom Validation Language Lines
|--------------------------------------------------------------------------
|
| Here you may specify custom validation messages for attributes using the
| convention "attribute.rule" to name the lines. This makes it quick to
| specify a specific custom language line for a given attribute rule.
|
*/
'custom' => [
'attribute-name' => [
'rule-name' => 'custom-message',
],
],
/*
|--------------------------------------------------------------------------
| Custom Validation Attributes
|--------------------------------------------------------------------------
|
| The following language lines are used to swap our attribute placeholder
| with something more reader friendly such as "E-Mail Address" instead
| of "email". This simply helps us make our message more expressive.
|
*/
'attributes' => [],
];
Как я могу подключить мой валидатор к валидации. php lang file?