How to return custom error message from controller method validation

cmac picture cmac · Oct 16, 2016 · Viewed 48.6k times · Source

How to return a custom error message using this format?

$this->validate($request, [
  'thing' => 'required'
]);

Answer

Imtiaz Pabel picture Imtiaz Pabel · Oct 16, 2016

to get custom error message you need to pass custom error message on third parameter,like that

$this->validate(
    $request, 
    ['thing' => 'required'],
    ['thing.required' => 'this is my custom error message for required']
);