Laravel 5 Send Errors to Email

前端 未结 9 673
野的像风
野的像风 2021-02-03 10:45

I am trying to figure out how I can send errors to my email in Laravel 5. I haven\'t had much luck finding any good resources.

There used to be good packages like: http

9条回答
  •  再見小時候
    2021-02-03 11:00

    EDIT: I found a 3rd party log system built for Laravel

    www.understand.io

    Very nice solution, doesn't email me, but this works for what I need.

    I played around with this and went through the Laravel core files and came up with something similar to what you see on an error page.

    You just need to create a view file that echos out $content for the email

    public function report(\Exception $e)
    {
        if ($e instanceof \Exception) {
    
            $debugSetting = Config::get('app.debug');
    
            Config::set('app.debug', true);
            if (ExceptionHandler::isHttpException($e)) {
                $content = ExceptionHandler::toIlluminateResponse(ExceptionHandler::renderHttpException($e), $e);
            } else {
                $content = ExceptionHandler::toIlluminateResponse(ExceptionHandler::convertExceptionToResponse($e), $e);
            }
    
            Config::set('app.debug', $debugSetting);
    
            $data['content'] = (!isset($content->original)) ? $e->getMessage() : $content->original;
    
            Mail::queue('errors.emails.error', $data, function ($m) {
                $m->to('email@email.com', 'Server Message')->subject('Error');
            });
        }
    
        return parent::report($e);
    }
    

提交回复
热议问题