PHP code example of encodia / laravel-something-wrong

1. Go to this page and download the library: Download encodia/laravel-something-wrong 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/ */

    

encodia / laravel-something-wrong example snippets



use \Encodia\SomethingWrong;

class MyService {
    private SomethingWrong $somethingWrong;

    public function __construct(SomethingWrong $somethingWrong)
    {        
        $this->somethingWrong = $somethingWrong;
    }
    
    public function doSomething(): void
    {
        // ...
        $this->somethingWrong
            ->exception(
                new \Exception("This wasn't supposed to happen, so let's notify it!")
        );
        
        // ...        
    }
}

    

use \Encodia\SomethingWrong\Facades\SomethingWrong;

// ...
SomethingWrong::exception(
    new \Exception("This wasn't supposed to happen, so let's notify it!")
);


SomethingWrong::exception(
    new \Exception("Something wrong happened!")
);


SomethingWrong::exception(
    new \Exception("Something wrong happened!"),
    [
        'foo' => 'bar',
        'path' => 'a/b/c',
        'user' => auth()->user,
    ],
);
bash
php artisan vendor:publish --tag="laravel-something-wrong-config"