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(6mo ago)3133.0k↓45%MITPHPPHP ^8.2CI passing

Since Aug 7Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/vaened/laravception)[ Packagist](https://packagist.org/packages/vaened/laravception)[ RSS](/packages/vaened-laravception/feed)WikiDiscussions master Synced 2d 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.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODI4NDIyNDEsIm5iZiI6MTc4Mjg0MTk0MSwicGF0aCI6Ii8xNTA3Nzg1MC8zNTU5NDgyNTEtMzVhNWMx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dXJlPTEwZjA2YzdkMGI3NWRmOWQwZTIzY2Y1MGUxM2NiMTFiM2ExNTU4ZmU1Mzg1NThmYzFlNzExY2IzNjBkYTYzMzAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnN2ZyUyQnhtbCJ9.PD0ltrKRCbVMT3ltsox_PsgwHFsc189djJVHXzL0Uvo)

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

46

—

FairBetter than 92% of packages

Maintenance67

Regular maintenance activity

Popularity34

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

191d ago

Major Versions

v0.2.2 → v1.0.02024-10-06

v1.0.1 → v2.0.02025-03-07

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15077850?v=4)[Enea Dhack](/maintainers/vaened)[@vaened](https://github.com/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

[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135224.7k7](/packages/statamic-rad-pack-runway)[api-platform/laravel

API Platform support for Laravel

58171.5k14](/packages/api-platform-laravel)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21318.6k3](/packages/ecotone-laravel)[duncanmcclean/statamic-cargo

Comprehensive e-commerce addon for Statamic. Build bespoke e-commerce sites without the complexity.

3416.9k](/packages/duncanmcclean-statamic-cargo)

PHPackages © 2026

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