PHPackages                             arrahmouni/response-helper - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. arrahmouni/response-helper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arrahmouni/response-helper
==========================

Response helper/builder for Laravel apps (web, ajax, api, internal).

1.0.6(2mo ago)0110MITPHPPHP ^8.2

Since Jan 25Pushed 2mo agoCompare

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

READMEChangelogDependencies (1)Versions (7)Used By (0)

Laravel Response Helper Package
===============================

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

[![Laravel Response Helper](https://camo.githubusercontent.com/49d9b290bfcf4ff2e8fec3937b392f77cba29c6acddbc808bb20c651bf346a37/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d526573706f6e73655f48656c7065722d627269676874677265656e)](https://camo.githubusercontent.com/49d9b290bfcf4ff2e8fec3937b392f77cba29c6acddbc808bb20c651bf346a37/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d526573706f6e73655f48656c7065722d627269676874677265656e)[![License](https://camo.githubusercontent.com/b8cadaa967891081f8f165695470689986c028821dd8a040132f6e661795dc0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c7565)](https://camo.githubusercontent.com/b8cadaa967891081f8f165695470689986c028821dd8a040132f6e661795dc0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c7565)

A fluent response builder + global helper functions for Laravel apps (web, ajax, api, internal).

📦 Features
----------

[](#-features)

- **Fluent Response Builder** via `app('response')`
- **Auto Output Mode** (API / Ajax / Web / Internal)
- **Publishable Config &amp; Translations**
- **Compatibility Helpers** (`send*Response()` functions)
- **Configurable Payload Keys** (rename `success`, `message`, `data`, `errors`, ...)

🚀 Installation
--------------

[](#-installation)

1. Install via Composer:

```
composer require arrahmouni/response-helper
```

2. Publish configuration and translations (optional):

```
php artisan vendor:publish --provider="ArRahmouni\ResponseHelper\ResponseServiceProvider" --tag=response-config
php artisan vendor:publish --provider="ArRahmouni\ResponseHelper\ResponseServiceProvider" --tag=response-lang
```

- **Config**: `config/response.php`
- **Lang**: `lang/vendor/response/{en,ar}/messages.php`

🛠 Configuration
---------------

[](#-configuration)

Edit `config/response.php` to customize:

```
return [
    'binding' => [
        'key' => 'response',
    ],
    'paths' => [
        'api_pattern' => 'api/*',
    ],
    'payload' => [
        'keys' => [
            'success' => 'success',
            'code'    => 'code',
            'message' => 'message',
            'data'    => 'data',
            'errors'  => 'errors',
        ],
        'api' => [
            'message_as_string'    => true,
            'cast_empty_to_object' => true,
        ],
    ],
];
```

🎯 Basic Usage
-------------

[](#-basic-usage)

Build and send a response:

```
return app('response')
    ->success()
    ->withDefaultMessage('data_loaded_successfully')
    ->withData([
        'items' => $items,
    ])
    ->send();
```

🔧 Output Modes
--------------

[](#-output-modes)

`send()` automatically selects the output format:

- **API**: JSON when the request matches `config('response.paths.api_pattern')` (default: `api/*`)
- **Ajax**: JSON when `request()->ajax()` or when you force it via `send(asAjax: true)`
- **Web (non-ajax)**:
    - redirect when `redirectTo()` was set
    - view when `view()` was set
    - otherwise `back()` with flash message + old input + errors
- **Internal**: array when `send(isInternal: true)`

🧰 Global Helper Functions
-------------------------

[](#-global-helper-functions)

This package autoloads `src/helpers.php` and provides:

- **Web/Ajax**

    - `sendSuccessResponse(?string $redirectTo = null, ?string $message = null, bool $withIntended = false, mixed $customMessage = null)`
    - `sendFailResponse(?string $message = null, ?string $customMessage = null)`
    - `sendValidationResponse(\Illuminate\Validation\Validator $validator)`
    - `sendExceptionResponse(\Exception $e)`
    - `sendUnauthorizedResponse(?string $redirectTo = null, string $message = 'login_required')`
    - `sendNotFoundResponse(string $message = 'record_not_found')`
    - `sendServerErrorResponse(?string $message = null)`
    - `sendMaintenanceModeResponse(string $message = 'under_maintenance')`
    - `sendDontHavePermissionResponse(string $message = 'dont_have_permission')`
    - `sendMethodNotAllowedResponse(string $message = 'method_not_allowed')`
- **Internal (always returns array)**

    - `sendSuccessInternalResponse(?string $message = null, array $data = [], ?string $customMessage = null)`
    - `sendFailInternalResponse(?string $message = null, array $errors = [], ?string $customMessage = null)`
- **API (JSON)**

    - `sendApiSuccessResponse(string $message = 'data_loaded_successfully', ?string $customMessage = null, array $data = [])`
    - `sendApiFailResponse(?string $message = null, ?string $customMessage = null, array $errors = [], array $data = [])`

🛡 Service Provider
------------------

[](#-service-provider)

The `ResponseServiceProvider` handles:

- Container binding (`response.binding.key`)
- Config + translations publishing
- Translation namespace registration (`response::messages.*`)

📜 License
---------

[](#-license)

This package is open-source software licensed under the [MIT license](LICENSE.md).

🤝 Contributing
--------------

[](#-contributing)

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

---

**Happy Response Building!**

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance83

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

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

Total

6

Last Release

86d ago

### Community

Maintainers

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

---

Top Contributors

[![arrahmouni](https://avatars.githubusercontent.com/u/49792530?v=4)](https://github.com/arrahmouni "arrahmouni (9 commits)")

---

Tags

responselaravelhelperar-rahmouni

### Embed Badge

![Health badge](/badges/arrahmouni-response-helper/health.svg)

```
[![Health](https://phpackages.com/badges/arrahmouni-response-helper/health.svg)](https://phpackages.com/packages/arrahmouni-response-helper)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M685](/packages/barryvdh-laravel-ide-helper)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)[mckenziearts/laravel-command

A simple Laravel package to provide artisan new commands

321.2k](/packages/mckenziearts-laravel-command)

PHPackages © 2026

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