PHPackages                             jftecnologia/laravel-exceptions - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. jftecnologia/laravel-exceptions

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

jftecnologia/laravel-exceptions
===============================

Advanced exception management for Laravel with enriched context, multiple logging channels, and user-friendly error messages

v1.0.3(3mo ago)0647↓50%21MITPHPPHP ^8.4CI passing

Since Feb 9Pushed 3mo agoCompare

[ Source](https://github.com/jftecnologia/laravel-exceptions)[ Packagist](https://packagist.org/packages/jftecnologia/laravel-exceptions)[ Docs](https://github.com/jftecnologia/laravel-exceptions)[ RSS](/packages/jftecnologia-laravel-exceptions/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (11)Versions (5)Used By (1)

Laravel Exceptions
==================

[](#laravel-exceptions)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e685cd6025e8f07acf4caa10dbd1d1e458498cf7f270dea64df52d663441783d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a667465636e6f6c6f6769612f6c61726176656c2d657863657074696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jftecnologia/laravel-exceptions)[![GitHub Tests Action Status](https://camo.githubusercontent.com/0640fdcb20ed40cf2394d6fd053432ea95c9441aed94cdcb0eb6bc8b126ba9a9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a667465636e6f6c6f6769612f6c61726176656c2d657863657074696f6e732f74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/jftecnologia/laravel-exceptions/actions?query=workflow%3Atests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/5d8c27809cbc79c1daefb49c8fde2469cea7e764b1acb64ab76f85151f9b33a2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a667465636e6f6c6f6769612f6c61726176656c2d657863657074696f6e732f6669782d7068702d636f64652d7374796c652e796d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/jftecnologia/laravel-exceptions/actions?query=workflow%3A%22fix-php-code-style-issues%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/952abd50514f1b827202ee82dbd9458dbaba74504dd627194e62304484f0bc1a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a667465636e6f6c6f6769612f6c61726176656c2d657863657074696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jftecnologia/laravel-exceptions)

Advanced exception management system for Laravel with enriched context, multiple logging channels, and customized user-facing messages.

Features
--------

[](#features)

- **Custom exceptions** with separate messages for developers and end-users
- **Enriched context** automatically collected (user, host, environment, stack trace)
- **Multiple channels** for storage (database, etc.)
- **Automatic conversion** of Symfony HTTP exceptions
- **Database logging** with complete schema
- **Internationalization** support (en, es, pt\_BR)
- **Artisan commands** for quick setup and exception generation

Installation
------------

[](#installation)

```
composer require jftecnologia/laravel-exceptions
```

### Quick Install (Recommended)

[](#quick-install-recommended)

Run the interactive installation command:

```
php artisan laravel-exceptions:install
```

This will guide you through publishing assets, migrations, configuration, and running migrations.

**After installation**, you must register the exception handler in your `bootstrap/app.php` file:

```
use JuniorFontenele\LaravelExceptions\Facades\LaravelException;

return Application::configure(basePath: dirname(__DIR__))
    // ... other configurations
    ->withExceptions(function (Exceptions $exceptions) {
        // ... other exception handlers

        // Register Laravel Exceptions handler (must be the last handler)
        LaravelException::handles($exceptions);
    })
    ->create();
```

**Note:** The `LaravelException::handles()` call must be placed as the **last handler** in the `withExceptions` method to ensure it properly catches all exceptions.

### Manual Installation

[](#manual-installation)

**Important:** You must publish the package assets and migrations before using it:

```
php artisan vendor:publish --tag="laravel-exceptions-assets"
```

```
php artisan vendor:publish --tag="laravel-exceptions-migrations"
php artisan migrate
```

Optionally, publish configuration (if you want to customize it):

```
php artisan vendor:publish --tag="laravel-exceptions-config"
```

Optionally, publish views (if you want to customize them):

```
php artisan vendor:publish --tag="laravel-exceptions-views"
```

**After publishing**, you must register the exception handler in your `bootstrap/app.php` file:

```
use JuniorFontenele\LaravelExceptions\Facades\LaravelException;

return Application::configure(basePath: dirname(__DIR__))
    // ... other configurations
    ->withExceptions(function (Exceptions $exceptions) {
        // ... other exception handlers

        // Register Laravel Exceptions handler (must be the last handler)
        LaravelException::handles($exceptions);
    })
    ->create();
```

**Note:** The `LaravelException::handles()` call must be placed as the **last handler** in the `withExceptions` method to ensure it properly catches all exceptions.

Usage
-----

[](#usage)

### Creating Custom Exceptions

[](#creating-custom-exceptions)

Use the artisan command to generate exception classes:

```
php artisan make:app-exception PaymentFailedException
```

This creates a new exception class in `app/Exceptions/PaymentFailedException.php`.

### Throwing Exceptions

[](#throwing-exceptions)

```
use JuniorFontenele\LaravelExceptions\Exceptions\AppException;

// Basic exception
throw new AppException(
    message: 'Internal system error',
    userMessage: 'An error occurred. Please try again.',
    statusCode: 500
);

// With additional context
throw new AppException(
    message: 'Payment processing failed',
    userMessage: 'Unable to process payment.',
    statusCode: 422,
    context: [
        'payment_id' => $paymentId,
        'amount' => $amount,
    ]
);
```

### HTTP Exceptions

[](#http-exceptions)

```
use JuniorFontenele\LaravelExceptions\Exceptions\Http\NotFoundHttpException;
use JuniorFontenele\LaravelExceptions\Exceptions\Http\UnauthorizedHttpException;

throw new NotFoundHttpException('Resource not found');
throw new UnauthorizedHttpException('Access denied');
```

Available classes: `BadRequestHttpException`, `UnauthorizedHttpException`, `AccessDeniedHttpException`, `NotFoundHttpException`, `MethodNotAllowedHttpException`, `SessionExpiredHttpException`, `UnprocessableEntityHttpException`, `TooManyRequestsHttpException`, `InternalServerErrorHttpException`, `ServiceUnavailableHttpException`, `GatewayTimeoutHttpException`.

### Cleaning Old Exception Records

[](#cleaning-old-exception-records)

Use the clean command to remove old exception records from the database:

```
# Clean records using the default retention period (configured in config file)
php artisan laravel-exceptions:clean

# Clean records older than a specific number of days
php artisan laravel-exceptions:clean --days=90

# Force execution in production without confirmation
php artisan laravel-exceptions:clean --force
```

The retention period defaults to 365 days but can be configured via the `delete_records_older_than_days` setting.

**Recommended:** Schedule this command to run daily by adding it to your `routes/console.php`:

```
use Illuminate\Support\Facades\Schedule;

Schedule::command('laravel-exceptions:clean --force')
    ->daily()
    ->onOneServer();
```

Configuration
-------------

[](#configuration)

Main options in `config/laravel-exceptions.php`:

```
return [
    // Custom error view
    'view' => 'laravel-exceptions::error',

    // Convert unhandled exceptions to AppException
    'convert_exceptions' => env('LARAVEL_EXCEPTIONS_CONVERT_EXCEPTIONS', true),

    // Render custom exceptions even in debug mode
    'render_in_debug' => env('LARAVEL_EXCEPTIONS_RENDER_IN_DEBUG', false),

    // Days to keep exception records (used by clean command)
    'delete_records_older_than_days' => 365,

    // Automatic context providers
    'context_providers' => [
        AppExceptionContextProvider::class,
        AppContextProvider::class,
        HostContextProvider::class,
        UserContextProvider::class,
        ExceptionContextProvider::class,
        PreviousExceptionContextProvider::class,
    ],

    // Storage channels
    'channels' => [
        'database' => Database::class,
    ],

    // Channel-specific settings
    'channels_settings' => [
        'database' => [
            'table_name' => 'exceptions_log',
            'model' => Exception::class,
            'user_model' => config('auth.providers.users.model'),
            'user_model_table' => 'users',
        ],
    ],

    // Ignored exceptions (won't be logged or converted)
    'ignored_exceptions' => [
        AuthenticationException::class,
        ValidationException::class,
    ],

    // HTTP exception mappings
    'http_exceptions' => [
        400 => BadRequestHttpException::class,
        401 => UnauthorizedHttpException::class,
        403 => AccessDeniedHttpException::class,
        404 => NotFoundHttpException::class,
        // ... more status codes
    ],
];
```

### Configuration Options

[](#configuration-options)

OptionDefaultDescription`view``laravel-exceptions::error`Blade view used for displaying exceptions`convert_exceptions``true`Convert unhandled exceptions to AppException automatically`render_in_debug``false`Render custom exception views even when `APP_DEBUG=true``delete_records_older_than_days``365`Number of days to retain exception records (used by clean command)`context_providers`ArrayClasses that provide additional context for exceptions`channels`ArrayStorage channels for logging exceptions`channels_settings`ArrayChannel-specific configuration options`ignored_exceptions`ArrayException classes that should not be logged or converted`http_exceptions`ArrayMapping of HTTP status codes to exception classesAutomatic Context
-----------------

[](#automatic-context)

The package automatically collects:

- **Exception**: class, message, file, line, code, stack trace
- **Application**: environment, debug mode
- **Host**: hostname, IP address
- **User**: authenticated user ID
- **Previous exception**: complete information if exists

Database Storage
----------------

[](#database-storage)

Exceptions are automatically saved to the `exceptions_log` table with all relevant fields, making analysis and debugging easier.

Testing
-------

[](#testing)

```
composer test
```

Credits
-------

[](#credits)

- [Junior Fontenele](https://github.com/juniorfontenele)

License
-------

[](#license)

MIT License. See [LICENSE.md](LICENSE.md) for details.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance82

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

4

Last Release

94d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3694405?v=4)[Junior Fontenele](/maintainers/juniorfontenele)[@juniorfontenele](https://github.com/juniorfontenele)

---

Top Contributors

[![juniorfontenele](https://avatars.githubusercontent.com/u/3694405?v=4)](https://github.com/juniorfontenele "juniorfontenele (5 commits)")

---

Tags

laravellogginglaravel-packageexceptionsContexterror handlingexception handlererror-messages

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/jftecnologia-laravel-exceptions/health.svg)

```
[![Health](https://phpackages.com/badges/jftecnologia-laravel-exceptions/health.svg)](https://phpackages.com/packages/jftecnologia-laravel-exceptions)
```

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[bugsnag/bugsnag-laravel

Official Bugsnag notifier for Laravel applications.

90334.6M36](/packages/bugsnag-bugsnag-laravel)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

416632.8k5](/packages/yadahan-laravel-authentication-log)[inspector-apm/inspector-laravel

Code Execution Monitoring, built for developers.

2332.0M2](/packages/inspector-apm-inspector-laravel)[shaffe/laravel-mail-log-channel

A package to support logging via email in Laravel

1286.2k](/packages/shaffe-laravel-mail-log-channel)[cerbero/exception-handler

Extend Laravel exception handler to define how to handle custom exceptions via service providers.

607.5k](/packages/cerbero-exception-handler)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
