PHPackages                             vaened/laravception - 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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. vaened/laravception

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

vaened/laravception
===================

Standardize your error responses in Laravel with Laravception. Get consistent error codes, messages, metadata, and translation support.

v2.1.0(4mo ago)2127.0k↓14.4%MITPHPPHP ^8.2CI passing

Since Aug 7Pushed 4mo ago1 watchersCompare

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

READMEChangelog (3)Dependencies (6)Versions (11)Used By (0)

Laravception
============

[](#laravception)

[![Build Status](https://github.com/vaened/laravception/actions/workflows/tests.yml/badge.svg)](https://github.com/vaened/laravception/actions?query=workflow:Tests)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](license)

Laravception standardizes error responses in Laravel, ensuring all exceptions have a unique code, clear message, and metadata. It supports error message translation, promotes specific exception classes, and adapts details based on the environment.

[![Carbon source code](https://private-user-images.githubusercontent.com/15077850/355948251-35a5c171-316b-478b-879c-0324961d38ef.svg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQ2NzY5OTMsIm5iZiI6MTc3NDY3NjY5MywicGF0aCI6Ii8xNTA3Nzg1MC8zNTU5NDgyNTEtMzVhNW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mNjNiYTE4NjRjMDA2OTM1Zjk4OTJmYTRiYmU1NWYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.6SuaebaYqs28x2LHPa6zpVTNN04A9D3_iZDT-5vdbxo)

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

[](#installation)

Laravception requires PHP 8.2. To get the latest version, simply require the project using Composer:

```
composer require vaened/laravception
```

Now. Publish the configuration file.

```
php artisan vendor:publish --tag='laravception'
```

Usage
-----

[](#usage)

Laravception captures exceptions thrown by the application and standardizes their structure. The unified structure is as follows:

```
{
  "code": "Exception error code",
  "message": "Exception message",
  "params": {
    "Exception parameters"
  },
  "meta": [
    "Metadata that the exception might export"
  ],
  "tags": [
    "Classifications tags for the exception"
  ],
  "exception": "Exception name",
  "file": "File where exception was thrown",
  "line": "Line that threw the exception",
  "trace": [
    "Full stack trace of the exception"
  ]
}
```

`This structure will hide certain details based on whether the environment is set to development or production.`

### Translations

[](#translations)

To enable exception translation, implement the interface [TranslatableException](./src/Exceptions/TranslatableException.php). This is sufficient to start translating child exceptions.

```
final class InvalidCreditCardException extends RuntimeException implements TranslatableException
{
  // this is enough
}
```

It’s recommended to create a custom exception class for each error to allow more specific translations. For example, with the exception ***“InvalidCreditCardException”***, you can have a translation entry in the **exceptions** file:**exceptions**:

```
[
  "invalid_credit_card_exception" => "La tarjeta de credito ingresada no es válida".
]
```

This functionality is enabled by default. Any exceptions that do not implement [Codeable](./src/Exceptions/Codeable.php) will be treated in the same manner, converting the class name to snake\_case and using this transformation as the error code and key for the translation.

For better error code management, you can implement [Codeable](./src/Exceptions/Codeable.php). In the exception ***"InvalidCreditCardException"***, you can return a custom error code such as **payments.invalid\_credit\_card**, and in your translation file:

```
[
  "payments" => [
    "invalid_credit_card" => "La tarjeta de crédito ingresada no es válida".
  ]
]
```

You can also add parameters by implementing the [Parametrizable](./src/Exceptions/Parametrizable.php) interface. Return an array with the properties to be used, and your translation file will look like this:

```
[
  "payments" => [
    "invalid_credit_card" => "La tarjeta de crédito  no es válida".
  ]
]
```

We can finally have this implementation:

```
final class InvalidCreditCardException extends RuntimeException
	implements TranslatableException, Codeable, Parametrizable
{
    public function __construct(private readonly string $cardNumber)
    {
        parent::__construct("The credit card number  is invalid");
    }

    public function errorCode(): string
    {
        return 'payments.invalid_credit_card';
    }

    public function parameters(): array
    {
        return [
            'card_number' => $this->cardNumber,
        ];
    }
}
```

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

[](#configuration)

To understand the various configuration options, please refer to the comments in the configuration file [laravception.php](./config/laravception.php).

Principles
----------

[](#principles)

The core idea behind this library is to standardize error messages in a Laravel project, ensuring that all exceptions follow a common structure.

Specific Exceptions
-------------------

[](#specific-exceptions)

To improve API organization and documentation, it is recommended to create custom exceptions with a specific purpose, such as ***"PaymentFailedException"*** or ***"ClientNotFoundException"*** This allows for more precise and effective handling of exceptions.

Translation of Messages
-----------------------

[](#translation-of-messages)

With specific exceptions, presenting error messages can be automated using unique codes. This makes it easier to translate and decorate error messages, ensuring they are clear and useful for both developers and end-users.

License
-------

[](#license)

This library is licensed under the MIT License. For more information, please see the [`license`](./license) file.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance74

Regular maintenance activity

Popularity34

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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 ~56 days

Recently: every ~111 days

Total

10

Last Release

145d ago

Major Versions

v0.2.2 → v1.0.02024-10-06

v1.0.1 → v2.0.02025-03-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/ebfa2dc9bcd9f9f7cea1f5473811d3c3904f60716e5605ab0d7208a9a6b81f09?d=identicon)[vaened](/maintainers/vaened)

---

Top Contributors

[![vaened](https://avatars.githubusercontent.com/u/15077850?v=4)](https://github.com/vaened "vaened (42 commits)")

---

Tags

error-handlingexceptionsexceptions-handlinglaravel-libraryexceptionserror handlinglaravel-libraryexceptions-handling

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vaened-laravception/health.svg)

```
[![Health](https://phpackages.com/badges/vaened-laravception/health.svg)](https://phpackages.com/packages/vaened-laravception)
```

###  Alternatives

[vasek-purchart/tracy-blue-screen-bundle

This bundle lets you use the Tracy's debug screen in combination with the the default profiler in your Symfony application.

1177.6k](/packages/vasek-purchart-tracy-blue-screen-bundle)

PHPackages © 2026

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