Laravel 5.x, 6.x and 7.x

Install

Install the sentry/sentry-laravel package:

Copied
composer require sentry/sentry-laravel

Add Sentry reporting to App/Exceptions/Handler.php.

App/Exceptions/Handler.php
Copied
public function report(Exception $exception)
{
    if ($this->shouldReport($exception) && app()->bound('sentry')) {
        app('sentry')->captureException($exception);
    }

    parent::report($exception);
}

If you're on Laravel 5.5 or later the package will be auto-discovered. Otherwise you will need to manually configure it in your config/app.php.

config/app.php
Copied
'providers' => array(
    // ...
    Sentry\Laravel\ServiceProvider::class,
),
'aliases' => array(
    // ...
    'Sentry' => Sentry\Laravel\Facade::class,
),

Configure

Run:

Copied
php artisan sentry:publish

that creates the Sentry configuration file (config/sentry.php).

Afterwards, add your DSN to .env:

.env
Copied
SENTRY_LARAVEL_DSN=https://examplePublicKey@o0.ingest.sentry.io/0

Verify with Artisan

You can test your configuration using the provided artisan command:

Copied
php artisan sentry:test --transaction
[Sentry] DSN discovered!
[Sentry] Generating test Event
[Sentry] Sending test Event
[Sentry] Transaction sent: b22f130764c940c69d6860c212849d48
[Sentry] Event sent with ID: 4cde238791a9433c8876f4a545d9a95b

Verify with code

You can easily verify that Sentry is capturing errors in your Laravel application by creating a debug route that will throw an exception:

Copied
Route::get('/debug-sentry', function () {
    throw new Exception('My first Sentry error!');
});

Visiting this route will trigger an exception that will be captured by Sentry.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").