How to return custom error message from controller method validation

How to return a custom error message using this format?

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

Answer

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']
);

Leave a Reply

Your email address will not be published. Required fields are marked *