PHP code example of najibismail / laravel-exception-catcher
1. Go to this page and download the library: Download najibismail/laravel-exception-catcher 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/ */
najibismail / laravel-exception-catcher example snippets
use NajibIsmail\LaravelExceptionCatcher\Traits\SendsExceptionEmails;
class Handler extends ExceptionHandler
{
use SendsExceptionEmails;
// The trait automatically handles exception reporting
// No need to override the report() method
}
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use NajibIsmail\LaravelExceptionCatcher\Traits\SendsExceptionEmails;
use Throwable;
class Handler extends ExceptionHandler
{
use SendsExceptionEmails;
// The trait automatically overrides the report() method
// No additional code needed
}
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
class Handler extends ExceptionHandler
{
public function report(Throwable $exception)
{
parent::report($exception);
// Send exception email
if (app()->bound('exception.emailer')) {
app('exception.emailer')->handle($exception, request());
}
}
}
use NajibIsmail\LaravelExceptionCatcher\Facades\ExceptionCatcher;
try {
// Your code here
} catch (Exception $e) {
ExceptionCatcher::handle($e, request());
throw $e; // Re-throw if needed
}