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. [API Development](/categories/api)
4. /
5. bhry98/laravel-api-response

ActiveLibrary[API Development](/categories/api)

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

laravel package for handle responses for api projects

v1.0.0(3mo ago)0370MITPHP

Since Jan 21Pushed 1mo agoCompare

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

READMEChangelog (2)Dependencies (1)Versions (2)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

37

—

LowBetter than 83% of packages

Maintenance86

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

118d ago

### 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)")

### 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

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[echolabsdev/prism

A powerful Laravel package for integrating Large Language Models (LLMs) into your applications.

2.3k388.3k10](/packages/echolabsdev-prism)[sburina/laravel-whmcs-up

WHMCS API client and user provider for Laravel

271.3k](/packages/sburina-laravel-whmcs-up)

PHPackages © 2026

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