user1157885
user1157885

Reputation: 2069

Laravel $e->getMessage empty on Request validation error

I'm trying to setup custom error handlers in Handler.php but when I try to get the error message when a Request validation isn't met I get an empty response.

public function render($request, Exception $e)
{
    dd($e->getMessage());
    return parent::render($request, $e);
}

My rules are set to:

'min:10'

So when I don't provide parameters of length 10 I want it to output that error within $e->getMessage() so I can do whatever I want to do with it, but the error is always empty. What am i doing wrong?

Upvotes: 0

Views: 1538

Answers (1)

Exception will not give you errors that occurs for Validator.

Validator error are sent on its object and by errors() method. So, after calling the errors method on a Validator instance, you will receive an Illuminate\Support\MessageBag instance, which has a variety of convenient methods for working with error messages.

For more details: https://laravel.com/docs/5.2/validation#custom-error-messages

Upvotes: 2

Related Questions