I read custom messages in laravel 5.4:
https://laravel.com/docs/5.4/validation#custom-error-messages .

Is it possible, besides the field name, to indicate its invalid values?
Sort of:

$messages = [ 'unique' => "The :attribute ':value' has already been taken", 'required' => "The ':attribute' field is required.", ]; $validator = Validator::make( $dataArray , $rules, $messages ); ... 
  • And what's the point? All fields are filled and so on. - Maxim Stepanov

1 answer 1

There is a workaround on the Laracast forum

namespace App \ Services;

 use Illuminate\Validation\Validator as BaseValidator; use Illuminate\Support\Arr; class CustomValidator extends BaseValidator { protected function validateUniqueName($attribute, $value, $parameters) { // make use of parent validator validateUnique method. return $this->validateUnique($attribute, $value, $parameters); } protected function replaceUniqueName($message, $attribute, $rule, $parameters) { // parent class $data attribute contains all the validated values. $name = Arr::get($this->data, $attribute); return str_replace([':value'], [$name], $message); } } 

and then in AppServiceProvider:

 Validator::resolver(function($translator, $data, $rules, $messages) { return new \App\Services\CustomValidator($translator, $data, $rules, $messages); });