{ "html": "
\n

Installation

\n

There are various ways to install the PHP integration for Sentry. The\nrecommended way is to use Composer:

\n
$ composer require "sentry/sentry"\n
\n
\n

Alternatively you can manually install it:

\n
    \n
  1. Download and extract the latest sentry-php archive\nto your PHP project.

    \n
  2. \n
  3. Require the autoloader in your application:

    \n
    require_once '/path/to/Raven/library/Raven/Autoloader.php';\nRaven_Autoloader::register();\n
    \n
    \n
  4. \n
\n
\n\n\n
\n

Laravel 5.x

\n

Install the sentry/sentry-laravel package:

\n
$ composer require sentry/sentry-laravel\n
\n
\n

If you’re on Laravel 5.4 or earlier, you’ll need to add the following to your config/app.php (for Laravel 5.5+ these will be auto-discovered by Laravel):

\n
'providers' => array(\n    // ...\n    Sentry\\SentryLaravel\\SentryLaravelServiceProvider::class,\n)\n\n'aliases' => array(\n    // ...\n    'Sentry' => Sentry\\SentryLaravel\\SentryFacade::class,\n)\n
\n
\n

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

\n
public function report(Exception $exception)\n{\n    if (app()->bound('sentry') && $this->shouldReport($exception)) {\n        app('sentry')->captureException($exception);\n    }\n\n    parent::report($exception);\n}\n
\n
\n

Create the Sentry configuration file (config/sentry.php):

\n
$ php artisan vendor:publish --provider="Sentry\\SentryLaravel\\SentryLaravelServiceProvider"\n
\n
\n

Add your DSN to .env:

\n
SENTRY_DSN=___DSN___\n
\n
\n

Finally, if you wish to wire up User Feedback, you can do so by creating a custom\nerror view in resources/views/errors/500.blade.php.

\n

For Laravel 5 up to 5.4 you need to open up App/Exceptions/Handler.php and extend the\nrender method to make sure the 500 error is rendered as a view correctly, in 5.5+ this\nstep is not required anymore an you can skip ahead to the next one:

\n
<?php\n\nclass Handler extends ExceptionHandler\n{\n    public function report(Exception $exception)\n    {\n        if (app()->bound('sentry') && $this->shouldReport($exception)) {\n            app('sentry')->captureException($exception);\n        }\n\n        parent::report($exception);\n    }\n\n    public function render($request, Exception $exception)\n    {\n        // Convert all non-http exceptions to a proper 500 http exception\n        // if we don't do this exceptions are shown as a default template\n        // instead of our own view in resources/views/errors/500.blade.php\n        if ($this->shouldReport($exception) && !$this->isHttpException($exception) && !config('app.debug')) {\n            $exception = new HttpException(500, 'Whoops!');\n        }\n\n        return parent::render($request, $exception);\n    }\n}\n
\n
\n

Next, create resources/views/errors/500.blade.php, and embed the feedback code:

\n
<div class="content">\n    <div class="title">Something went wrong.</div>\n\n    @if(app()->bound('sentry') && !empty(Sentry::getLastEventID()))\n        <div class="subtitle">Error ID: {{ Sentry::getLastEventID() }}</div>\n\n        <!-- Sentry JS SDK 2.1.+ required -->\n        <script src="https://cdn.ravenjs.com/3.3.0/raven.min.js"></script>\n\n        <script>\n            Raven.showReportDialog({\n                eventId: '{{ Sentry::getLastEventID() }}',\n                // use the public DSN (dont include your secret!)\n                dsn: 'https://e9ebbd88548a441288393c457ec90441@sentry.io/3235',\n                user: {\n                    'name': 'Jane Bloggs',\n                    'email': 'jane.doe@example.com',\n                }\n            });\n        </script>\n    @endif\n</div>\n
\n
\n

That’s it!

\n
\n", "link": "https://docs.getsentry.com/clients/php/integrations/laravel/", "id": "php-laravel", "name": "Laravel" }