php-laravel.json 12 KB

123456
  1. {
  2. "html": "<div class=\"section\" id=\"installation\">\n<h2>Installation</h2>\n<p>There are various ways to install the PHP integration for Sentry. The\nrecommended way is to use <a class=\"reference external\" href=\"http://getcomposer.org/\">Composer</a>:</p>\n<div class=\"highlight-python\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span>$ composer require &quot;sentry/sentry&quot;\n</pre></div>\n</div>\n<p>Alternatively you can manually install it:</p>\n<ol class=\"arabic\">\n<li><p class=\"first\">Download and extract the latest <a class=\"reference external\" href=\"https://github.com/getsentry/sentry-php/archive/master.zip\">sentry-php</a> archive\nto your PHP project.</p>\n</li>\n<li><p class=\"first\">Require the autoloader in your application:</p>\n<div class=\"highlight-php\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">require_once</span> <span style=\"color: #e8535a\">&#39;/path/to/Raven/library/Raven/Autoloader.php&#39;</span><span style=\"color: #111111\">;</span>\n<span style=\"color: #111111\">Raven_Autoloader</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">register</span><span style=\"color: #111111\">();</span>\n</pre></div>\n</div>\n</li>\n</ol>\n</div>\n\n\n<div class=\"section\" id=\"laravel-5-x\">\n<h2>Laravel 5.x</h2>\n<p>Install the <code class=\"docutils literal\"><span class=\"pre\">sentry/sentry-laravel</span></code> package:</p>\n<div class=\"highlight-bash\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span>$ composer require sentry/sentry-laravel\n</pre></div>\n</div>\n<p>If you&#8217;re on Laravel 5.4 or earlier, you&#8217;ll need to add the following to your <code class=\"docutils literal\"><span class=\"pre\">config/app.php</span></code> (for Laravel 5.5+ these will be auto-discovered by Laravel):</p>\n<div class=\"highlight-php\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #e8535a\">&#39;providers&#39;</span> <span style=\"color: #4b4f5c\">=&gt;</span> <span style=\"color: #2eb0f7\">array</span><span style=\"color: #111111\">(</span>\n <span style=\"color: #34c08b; font-style: italic\">// ...</span>\n <span style=\"color: #111111\">Sentry\\SentryLaravel\\SentryLaravelServiceProvider</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">class</span><span style=\"color: #111111\">,</span>\n<span style=\"color: #111111\">)</span>\n\n<span style=\"color: #e8535a\">&#39;aliases&#39;</span> <span style=\"color: #4b4f5c\">=&gt;</span> <span style=\"color: #2eb0f7\">array</span><span style=\"color: #111111\">(</span>\n <span style=\"color: #34c08b; font-style: italic\">// ...</span>\n <span style=\"color: #e8535a\">&#39;Sentry&#39;</span> <span style=\"color: #4b4f5c\">=&gt;</span> <span style=\"color: #111111\">Sentry\\SentryLaravel\\SentryFacade</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">class</span><span style=\"color: #111111\">,</span>\n<span style=\"color: #111111\">)</span>\n</pre></div>\n</div>\n<p>Add Sentry reporting to <code class=\"docutils literal\"><span class=\"pre\">App/Exceptions/Handler.php</span></code>:</p>\n<div class=\"highlight-php\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">function</span> <span style=\"color: #111111\">report(Exception</span> <span style=\"color: #111111\">$exception)</span>\n<span style=\"color: #111111\">{</span>\n <span style=\"color: #2eb0f7\">if</span> <span style=\"color: #111111\">(app()</span><span style=\"color: #4b4f5c\">-&gt;</span><span style=\"color: #a47ac6\">bound</span><span style=\"color: #111111\">(</span><span style=\"color: #e8535a\">&#39;sentry&#39;</span><span style=\"color: #111111\">)</span> <span style=\"color: #4b4f5c\">&amp;&amp;</span> <span style=\"color: #111111\">$this</span><span style=\"color: #4b4f5c\">-&gt;</span><span style=\"color: #a47ac6\">shouldReport</span><span style=\"color: #111111\">($exception))</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #111111\">app(</span><span style=\"color: #e8535a\">&#39;sentry&#39;</span><span style=\"color: #111111\">)</span><span style=\"color: #4b4f5c\">-&gt;</span><span style=\"color: #a47ac6\">captureException</span><span style=\"color: #111111\">($exception);</span>\n <span style=\"color: #111111\">}</span>\n\n <span style=\"color: #2eb0f7\">parent</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">report</span><span style=\"color: #111111\">($exception);</span>\n<span style=\"color: #111111\">}</span>\n</pre></div>\n</div>\n<p>Create the Sentry configuration file (<code class=\"docutils literal\"><span class=\"pre\">config/sentry.php</span></code>):</p>\n<div class=\"highlight-bash\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span>$ php artisan vendor:publish --provider<span style=\"color: #4b4f5c\">=</span><span style=\"color: #e8535a\">&quot;Sentry\\SentryLaravel\\SentryLaravelServiceProvider&quot;</span>\n</pre></div>\n</div>\n<p>Add your DSN to <code class=\"docutils literal\"><span class=\"pre\">.env</span></code>:</p>\n<div class=\"highlight-bash\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">SENTRY_DSN</span><span style=\"color: #4b4f5c\">=</span>___DSN___\n</pre></div>\n</div>\n<p>Finally, if you wish to wire up User Feedback, you can do so by creating a custom\nerror view in <cite>resources/views/errors/500.blade.php</cite>.</p>\n<p>For Laravel 5 up to 5.4 you need to open up <code class=\"docutils literal\"><span class=\"pre\">App/Exceptions/Handler.php</span></code> and extend the\n<code class=\"docutils literal\"><span class=\"pre\">render</span></code> 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:</p>\n<div class=\"highlight-php\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #4b4f5c\">&lt;?</span><span style=\"color: #111111\">php</span>\n\n<span style=\"color: #2eb0f7\">class</span> <span style=\"color: #111111\">Handler</span> <span style=\"color: #2eb0f7\">extends</span> <span style=\"color: #111111\">ExceptionHandler</span>\n<span style=\"color: #111111\">{</span>\n <span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">function</span> <span style=\"color: #111111\">report(Exception</span> <span style=\"color: #111111\">$exception)</span>\n <span style=\"color: #111111\">{</span>\n <span style=\"color: #2eb0f7\">if</span> <span style=\"color: #111111\">(app()</span><span style=\"color: #4b4f5c\">-&gt;</span><span style=\"color: #a47ac6\">bound</span><span style=\"color: #111111\">(</span><span style=\"color: #e8535a\">&#39;sentry&#39;</span><span style=\"color: #111111\">)</span> <span style=\"color: #4b4f5c\">&amp;&amp;</span> <span style=\"color: #111111\">$this</span><span style=\"color: #4b4f5c\">-&gt;</span><span style=\"color: #a47ac6\">shouldReport</span><span style=\"color: #111111\">($exception))</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #111111\">app(</span><span style=\"color: #e8535a\">&#39;sentry&#39;</span><span style=\"color: #111111\">)</span><span style=\"color: #4b4f5c\">-&gt;</span><span style=\"color: #a47ac6\">captureException</span><span style=\"color: #111111\">($exception);</span>\n <span style=\"color: #111111\">}</span>\n\n <span style=\"color: #2eb0f7\">parent</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">report</span><span style=\"color: #111111\">($exception);</span>\n <span style=\"color: #111111\">}</span>\n\n <span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">function</span> <span style=\"color: #111111\">render($request,</span> <span style=\"color: #111111\">Exception</span> <span style=\"color: #111111\">$exception)</span>\n <span style=\"color: #111111\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">// Convert all non-http exceptions to a proper 500 http exception</span>\n <span style=\"color: #34c08b; font-style: italic\">// if we don&#39;t do this exceptions are shown as a default template</span>\n <span style=\"color: #34c08b; font-style: italic\">// instead of our own view in resources/views/errors/500.blade.php</span>\n <span style=\"color: #2eb0f7\">if</span> <span style=\"color: #111111\">($this</span><span style=\"color: #4b4f5c\">-&gt;</span><span style=\"color: #a47ac6\">shouldReport</span><span style=\"color: #111111\">($exception)</span> <span style=\"color: #4b4f5c\">&amp;&amp;</span> <span style=\"color: #4b4f5c\">!</span><span style=\"color: #111111\">$this</span><span style=\"color: #4b4f5c\">-&gt;</span><span style=\"color: #a47ac6\">isHttpException</span><span style=\"color: #111111\">($exception)</span> <span style=\"color: #4b4f5c\">&amp;&amp;</span> <span style=\"color: #4b4f5c\">!</span><span style=\"color: #111111\">config(</span><span style=\"color: #e8535a\">&#39;app.debug&#39;</span><span style=\"color: #111111\">))</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #111111\">$exception</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">HttpException(</span><span style=\"color: #45c2c9\">500</span><span style=\"color: #111111\">,</span> <span style=\"color: #e8535a\">&#39;Whoops!&#39;</span><span style=\"color: #111111\">);</span>\n <span style=\"color: #111111\">}</span>\n\n <span style=\"color: #2eb0f7\">return</span> <span style=\"color: #2eb0f7\">parent</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">render</span><span style=\"color: #111111\">($request,</span> <span style=\"color: #111111\">$exception);</span>\n <span style=\"color: #111111\">}</span>\n<span style=\"color: #111111\">}</span>\n</pre></div>\n</div>\n<p>Next, create <code class=\"docutils literal\"><span class=\"pre\">resources/views/errors/500.blade.php</span></code>, and embed the feedback code:</p>\n<div class=\"highlight-html\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span>&lt;div class=&quot;content&quot;&gt;\n &lt;div class=&quot;title&quot;&gt;Something went wrong.&lt;/div&gt;\n\n @if(app()-&gt;bound(&#39;sentry&#39;) &amp;&amp; !empty(Sentry::getLastEventID()))\n &lt;div class=&quot;subtitle&quot;&gt;Error ID: {{ Sentry::getLastEventID() }}&lt;/div&gt;\n\n &lt;!-- Sentry JS SDK 2.1.+ required --&gt;\n &lt;script src=&quot;https://cdn.ravenjs.com/3.3.0/raven.min.js&quot;&gt;&lt;/script&gt;\n\n &lt;script&gt;\n Raven.showReportDialog({\n eventId: &#39;{{ Sentry::getLastEventID() }}&#39;,\n // use the public DSN (dont include your secret!)\n dsn: &#39;https://e9ebbd88548a441288393c457ec90441@sentry.io/3235&#39;,\n user: {\n &#39;name&#39;: &#39;Jane Bloggs&#39;,\n &#39;email&#39;: &#39;jane.doe@example.com&#39;,\n }\n });\n &lt;/script&gt;\n @endif\n&lt;/div&gt;\n</pre></div>\n</div>\n<p>That&#8217;s it!</p>\n</div>\n",
  3. "link": "https://docs.getsentry.com/clients/php/integrations/laravel/",
  4. "id": "php-laravel",
  5. "name": "Laravel"
  6. }