Laravel 5 has the option to deal with validation in the controller and provide a custom message to a validation rule for a specific field, such as:
$this->validate($request,
['title' => 'required'],
['title.required' => 'The Title field is required.' ]
]);
However, since I can comfortably deal with custom names to validation rules from the lang/en/validation.php
file, I was wondering if is there a way to specify a custom name for the attribute from the validation in controller, such as:
$this->validate($request,
['title' => 'required'],
['title' => 'Title' ]
]);
This example of course will not work.
If you're on Laravel 5.0, you won't be able to do this. However, if you've moved to Laravel 5.1, you're in luck. 5.1 added the custom attributes as the fourth parameter.
So, if you're on 5.1, you can do this:
$this->validate(
$request,
['title' => 'required'],
[],
['title' => 'Title' ]
]);