PHPackages                             bhry98/laravel-api-response - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. bhry98/laravel-api-response

ActiveLibrary[HTTP &amp; Networking](/categories/http)

bhry98/laravel-api-response
===========================

A fluent, extensible, and highly configurable API response toolkit for Laravel applications.

v2.0.0(3w ago)0694MITPHPPHP ^8.2

Since Jan 21Pushed 4mo agoCompare

[ Source](https://github.com/bhry98/laravel-api-response)[ Packagist](https://packagist.org/packages/bhry98/laravel-api-response)[ Docs](https://github.com/bhry98/laravel-api-response)[ RSS](/packages/bhry98-laravel-api-response/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (2)Dependencies (12)Versions (4)Used By (0)

Laravel API Response Package
============================

[](#laravel-api-response-package)

A fluent, extensible, and developer-friendly API response builder for Laravel applications.

---

🚀 Features
----------

[](#-features)

- ✨ **Fluent Interface** — Chain methods to build responses easily.
- 🧩 **Response Types** — Supports `success`, `error`, `validation`, `not found`, and more.
- ⚙️ **Customizable Messages** — Override defaults or localize them.
- 🧱 **Macroable Support** — Extend response types dynamically.
- 🧮 **Meta Data Support** — Add pagination or extra info with `meta()`.
- 🌍 **Localization Ready** — Pull response messages from Laravel translations.
- 🔍 **Trace Support** — Optionally include exception traces for debugging.

---

📦 Installation
--------------

[](#-installation)

```
composer require bhry98/laravel-api-response
```

---

⚙️ Configuration
----------------

[](#️-configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="Bhry98\LaravelApiResponse\Providers\LaravelApiResponseServiceProvider" --tag=config
```

This will create `config/bhry98-api-response.php` where you can customize default messages:

```
return [
    'messages' => [
        'success' => 'Operation successful',
        'error' => 'An error occurred',
        'validation' => 'Validation failed',
        'not_found' => 'Resource not found',
        'internal' => 'Internal server error',
    ],
];
```

---

🧠 Usage Example
---------------

[](#-usage-example)

```
use Bhry98\LaravelApiResponse\Facades\BResponseSuccess;
use Bhry98\LaravelApiResponse\Facades\BResponseError;

Route::get('/{t}', function ($t) {
    return match ($t) {
        "success" => BResponseSuccess::make()
                ->message('Everything is fine!')
                ->data(['id' => 1])
                ->additions(['request_id' => uniqid()])
                ->toJson(),
        default => BResponseError::make()
                ->message('Something went wrong!')
                ->trace(new \Exception('Example'))
                ->toJson(),
    };
});
```

---

🧩 Example Response
------------------

[](#-example-response)

### ✅ Success

[](#-success)

```
{
  "status": "success",
  "message": "Everything is fine!",
  "data": { "id": 1 },
  "additions": { "request_id": "654adf..." },
  "meta": []
}
```

### ❌ Error

[](#-error)

```
{
  "status": "error",
  "message": "Something went wrong!",
  "trace": "Exception stack trace (optional)",
  "data": [],
  "additions": [],
  "meta": []
}
```

---

🧱 Extend Response (Macroable)
-----------------------------

[](#-extend-response-macroable)

```
BResponseSuccess::macro('withTimestamp', function () {
    return $this->additions(['timestamp' => now()]);
});

// Usage
return BResponseSuccess::make()
    ->withTimestamp()
    ->toJson();
```

---

🧩 Available Methods
-------------------

[](#-available-methods)

MethodDescription`make($options = [])`Initialize response`message($message)`Set response message`data($data)`Attach data payload`additions(array $extras)`Add custom key/value pairs`meta($info)`Add pagination/meta info`trace($exception)`Include exception trace`localize($key)`Use translation key for message`toJson()`Return `Illuminate\Http\JsonResponse`---

⚖️ License
----------

[](#️-license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/license/MIT).

---

Developed with ❤️ by **Bhry98**

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance84

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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

Total

3

Last Release

22d ago

Major Versions

v1.0.1 → v2.0.02026-07-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/953ea673ae5e75b34c73d362b902d47932dc15e033b2a36a080bd363dd21f227?d=identicon)[bhry98](/maintainers/bhry98)

---

Top Contributors

[![bhry98](https://avatars.githubusercontent.com/u/85765830?v=4)](https://github.com/bhry98 "bhry98 (6 commits)")

---

Tags

responsejsonapilaravelrestapi-response

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/bhry98-laravel-api-response/health.svg)

```
[![Health](https://phpackages.com/badges/bhry98-laravel-api-response/health.svg)](https://phpackages.com/packages/bhry98-laravel-api-response)
```

###  Alternatives

[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[illuminate/routing

The Illuminate Routing package.

1239.4M3.5k](/packages/illuminate-routing)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.5k60.6M10.5k](/packages/larastan-larastan)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

79227.1M229](/packages/laravel-mcp)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

818355.4k3](/packages/defstudio-telegraph)

PHPackages © 2026

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