PHP code example of wirebox / laravel-airbrake

1. Go to this page and download the library: Download wirebox/laravel-airbrake library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wirebox / laravel-airbrake example snippets




    //config/app.php
  
    'providers' => [
        Wirebox\LaravelAirbrake\ServiceProvider::class,
    ],

php artisan vendor:publish --provider="Wirebox\LaravelAirbrake\ServiceProvider"

//config/logging.php

    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single', 'airbrake'],
        ],

        'airbrake' => [
            'driver' => 'custom',
            'via' => Wirebox\LaravelAirbrake\AirbrakeLogger::class,
            'level' => 'error',
        ],
    ]


//bootstrap/app.php
->withExceptions(function (Exceptions $exceptions) {
        $exceptions->report(function (Throwable $th) { // The Exceptions collection will contain Throwable instances. Useful for reporting PHP fatal errors.
            if (App::environment('staging', 'production') ) {
                $airbrakeNotifier = App::make('Airbrake\Notifier');
                $airbrakeNotifier->notify($th);
            }
        });
    })...

//app/Exceptions/Handler.php

//bootstrap/app.php

$app->configureMonologUsing(function($monolog) use ($app) {
    $airbrakeNotifier = (new Wirebox\LaravelAirbrake\AirbrakeHandler($app))->handle();
    $monologHandler = new Airbrake\MonologHandler($airbrakeNotifier, Monolog\Logger::ERROR);
    $monolog->pushHandler($monologHandler);
});