Error handling in Laravel

0

I would like to know how to handle personalized messages in errors. For now I have this in app / Exceptions / Handler.php

public function render($request, Exception $e)
{    
    return response()->view('errors.error', ['error_message' => $e->getMessage()], 500);

}

And in the error.blade.php file located in the errors folder, I simply have a custom view so that the message comes out of some color but I would like to know if it is possible that for each type of error you can send a different message to the user on the screen.

    
asked by Santiago Muñoz 16.08.2016 в 16:06
source

1 answer

1

Hello, sorry for not being able to comment, but I still can not.

If possible and everything is explained here:

link

For example to validate fields, you should already know this:

'custom' => [
    'email' => [
        'required' => 'Necesitamos el e-mail chiquilin!!',
    ],
],

Or for example a custom validation such as:

link

public function boot()
{
    Validator::extend('validame', function($attribute, $value, $parameters, $validator) {
        if($value < 100){
           return "Estás más que reprobado";
        }
        return "aprobado"
    });
}

To which you can also add custom error messages: D

    
answered by 16.08.2016 / 22:32
source