Ad

Laravel 5 : Customize HTML Form Validation In Controller File

- 1 answer

I am using following code in controller file. I have an element name title in view form. Following code is showing correct validation. But, i need to customize this error.

$v = Validator::make($request->all(), [
    'title' => 'required|max:255',
  ]);

if ($v->fails())
{
    return redirect()->back()->withErrors($v->errors());
}
Ad

Answer

You can pass as third argument of Validator your custom messages.

$messages = [
    'title.required' => 'You need to insert a pretty title'
];
v = Validator::make($request->all(), [
     'title' => 'required|max:255',
  ], $messages
);
Ad
source: stackoverflow.com
Ad