问题描述:

I've been using Laravel 5 for some time now and I'm creating my own logging layer for my application.

Since I want to log my failed queries I decided to create a Service Provider for this.

In the Service Provider I got this code:

public function boot()

{

$this->app->error(function (QueryException $ex) {

dd('test');

});

}

This should work, but it doesn't. I get the following error:

Call to undefined method Illuminate\Foundation\Application::error()

Somebody knows whats changed here. Cause I can't find the error method in the Application or Container class. Haven't found anything on the forums/github repo yet.

网友答案:

In Laravel 5 catching errors works differently. Source

You do it inside app/Exceptions/Handler.php by editing the render() method:

public function render($request, Exception $e)
{
    if ($this->isHttpException($e))
    {
        return $this->renderHttpException($e);
    }

    else if ($e instanceof QueryException)
    {
        dd('test');
    }

    else
    {
        return parent::render($request, $e);
    }
}

Documentation: http://laravel.com/docs/master/errors#handling-errors

相关阅读:
Top