Legacy Laravel integration guide

Add Bugsnag to your legacy Laravel applications.

This integration supports Laravel 4 (and Laravel 5 running PHP 5.4 or lower). For newer applications, see the updated Laravel integration guide.


  1. Add bugsnag/bugsnag-laravel to your composer.json as follows:

    $ composer require "bugsnag/bugsnag-laravel:^1.7"
  2. Register our service provider in providers array in config/app.php:

    'providers' => [
  3. Register the Bugsnag alias in the aliases array in config/app.php:

    'aliases' => [
        'Bugsnag' => 'Bugsnag\BugsnagLaravel\BugsnagFacade',

Basic configuration

Create a config/bugsnag.php configuration file as follows:

$ php artisan config:publish bugsnag/bugsnag-laravel

To associate your application with a project in your Bugsnag dashboard, you’ll need to set your Integration API Key in app/config/packages/bugsnag/bugsnag-laravel/config.php:

return array(
  'api_key' => 'YOUR_API_KEY_HERE'

You can find this key immediately after creating a new project from your Bugsnag dashboard, or later on your project’s settings page.

If you’d like to configure Bugsnag further, check out the configuration options reference.

Reporting unhandled exceptions

Laravel 4

At this point, Bugsnag should be installed and configured, and any unhandled exceptions will be automatically detected and should appear in your Bugsnag dashboard.

Laravel 5

You can ensure that all unhandled exceptions are sent to Bugsnag by using our ExceptionHandler.

Remove the following line from app/Exceptions/Handler.php:

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

And replace it with the Bugsnag ExceptionHandler:

use Bugsnag\BugsnagLaravel\BugsnagExceptionHandler as ExceptionHandler;

Reporting handled exceptions

Reporting handled exceptions can be accomplished as follows:

try {
    // Some potentially crashy code
} catch (Exception $e) {

When reporting handled exceptions, it’s often helpful to send us custom diagnostic data or to adjust the severity of particular errors. For more information, see reporting handled errors.

Sending diagnostic data

Automatically captured diagnostics

Bugsnag will automatically capture the following data for every exception:

  • A full stacktrace
  • Request information, including ip, headers, URL, HTTP method, and HTTP params
  • Session and cookie data
  • Release stage (production, beta, staging, etc)
  • Hostname

Custom diagnostics

It is often helpful to send us additional application-specific diagnostic data. This can be accomplished as follows:

Bugsnag::setBeforeNotifyFunction(function ($error) {
      'account' => [
          'name' => 'Acme Co.',
          'paying_customer' => true,

For more information, see the customizing error reports reference.

Identifying users

In order to correlate errors with customer reports, or to see a list of users who experienced each error, it is helpful to capture and display user information on your Bugsnag dashboard.

If you are Laravel’s built-in authentication, we will attempt to automatically capture information about the currently authenticated user and send this to your Bugsnag dashboard.

If you are using a different authentication system, you can set this information as follows by putting the following in the boot method of a service provider:

Bugsnag::setBeforeNotifyFunction(function ($error) {
        'id' => '123456',
        'name' => 'Leeroy Jenkins',
        'email' => 'leeeeroy@jenkins.com',

For more information, see configuration options.

Tracking deploys

By sending your source revision or application version to us when you deploy a new version of your app, you’ll be able to see which deploy each error was introduced in, or seen in.

See our deploy tracking guide for more details.

Next steps