PHPackages                             abdulbaset/response-format-trait - 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. abdulbaset/response-format-trait

ActiveLibrary[API Development](/categories/api)

abdulbaset/response-format-trait
================================

A PHP package for standardizing and formatting API and web responses.

1.1.2(2y ago)838MITPHPPHP ^8.0

Since Dec 23Pushed 2y ago2 watchersCompare

[ Source](https://github.com/AbdulBasetRS/Response-Format-Trait)[ Packagist](https://packagist.org/packages/abdulbaset/response-format-trait)[ Docs](https://digitalatum.com)[ RSS](/packages/abdulbaset-response-format-trait/feed)WikiDiscussions main Synced yesterday

READMEChangelog (1)Dependencies (2)Versions (14)Used By (0)

Documentation
=============

[](#documentation)

Response-Format-Trait
---------------------

[](#response-format-trait)

This PHP package provides a simple and consistent way to format API and web responses. It includes a set of predefined HTTP status codes with detailed messages and supports both API and web response formatting. The package is designed to be easy to integrate into any PHP Laravel project, with a particular focus on Laravel applications.

Features
--------

[](#features)

- Standardized API and web response formatting.
- Predefined HTTP status codes with detailed messages.
- Easy integration into Laravel projects.

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

[](#installation)

Use [Composer](https://getcomposer.org/) to install the package:

You can install this package via Composer:

```
composer require abdulbaset/response-format-trait
```

To update the `abdulbaset/response-format-trait` package in your Laravel project, you can use Composer's update command. Here's how you can do it:

```
composer update abdulbaset/response-format-trait
```

After running the update command in your Laravel project directory, and Composer will check for updates to the `abdulbaset/response-format-trait` package and its dependencies. If a newer version is available, Composer will download and install it, updating your project.

Usage
-----

[](#usage)

1. Publishing Configuration File You can publish the configuration file or language files using the following command:

```
php artisan vendor:publish --provider="Abdulbaset\ResponseFormatTrait\Providers\ResponseFormatTraitServiceProvider" --tag="config"
php artisan vendor:publish --provider="Abdulbaset\ResponseFormatTrait\Providers\ResponseFormatTraitServiceProvider" --tag="lang"
```

This command will copy the `response-format.php` file to your config directory, allowing you to customize the package's behavior.

1. Generating Responses

- First example

```
use Abdulbaset\ResponseFormatTrait\Respond;

class YourController extends Controller
{
    use Respond;

    public function someMethod()
    {
        // Example usage:
        return $this->formatApi(200, 'Success', 'Resource created successfully', $data);
    }
}
```

- The second example This will generate a JSON response with the provided status code, message, details, and optional data.

```
use Abdulbaset\ResponseFormatTrait\Respond;

class YourController extends Controller
{
    public function someMethod()
    {
        // Example usage:
        return  Respond::formatApi(200);
    }
}
```

- Checks if a given language is supported

```
use Abdulbaset\ResponseFormatTrait\Respond;

class YourController extends Controller
{
    public function someMethod()
    {
        if (Respond::isLanguageSupported('en')) {
            // English language is supported
            // Perform actions accordingly
        } else {
            // English language is not supported
            // Handle unsupported language scenario
        }
    }
}
```

This method validates whether a given language code is supported within the Respond trait. It checks if the provided language code exists within the predefined list of supported languages. If the language code is found in the list, the method returns true, indicating that the language is supported. Otherwise, it returns false.

Examples
--------

[](#examples)

Here are some examples of how you can use the `Respond` trait in your controllers:

1. here you can customize message and details response as you need. [![Screenshot 1](/media/version-1.1.1/example-1.png)](/media/version-1.1.1/example-1.png)and you will get the response like: [![Screenshot 1](/media/version-1.1.1/example-1-response.png)](/media/version-1.1.1/example-1-response.png)
2. here you can change the default language to get message and details for some specific local as you need. [![Screenshot 1](/media/version-1.1.1/example-2.png)](/media/version-1.1.1/example-2.png)and you will get the response like: [![Screenshot 1](/media/version-1.1.1/example-2-response.png)](/media/version-1.1.1/example-2-response.png)other example for 404 not found error [![Screenshot 1](/media/version-1.1.1/example-3.png)](/media/version-1.1.1/example-3.png)and you will get the response like: [![Screenshot 1](/media/version-1.1.1/example-3-response.png)](/media/version-1.1.1/example-3-response.png)
3. if you want set the dynamically local language you can make middleware and set inside `config(['response-format.language' => config('app.local', 'en')]);`[![Screenshot 1](/media/version-1.1.1/example-4.png)](/media/version-1.1.1/example-4.png)and you will get the response like: [![Screenshot 1](/media/version-1.1.1/example-4-response.png)](/media/version-1.1.1/example-4-response.png)
4. if you want check the package is supported the language or not, you can use this `Respond::isLanguageSupported($language)` static method. [![Screenshot 1](/media/version-1.1.1/example-5.png)](/media/version-1.1.1/example-5.png)

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

[](#configuration)

You can customize the behavior of the package by modifying the `response-format.php` configuration file. The available options are:

**Supported languages**:

- 'en': English
- 'de': German
- 'fr': French
- 'ar': Arabic
- 'es': Spanish
- 'it': Italian

If set to null, the language will be determined dynamically.

Author
------

[](#author)

The package was created by Abdulbaset R. Sayed

Contributing
------------

[](#contributing)

Contributions are welcome! If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request on GitHub.

License
-------

[](#license)

This Package is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

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

Recently: every ~0 days

Total

13

Last Release

757d ago

PHP version history (2 changes)1.0.3PHP ^7.4

1.0.7PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1d770636a8684f5b3bb07c0871140986c12f0f9a225d97d3b5fca53a5d7bdca0?d=identicon)[AbdulBasetRS](/maintainers/AbdulBasetRS)

---

Top Contributors

[![AbdulbasetRS](https://avatars.githubusercontent.com/u/74756037?v=4)](https://github.com/AbdulbasetRS "AbdulbasetRS (18 commits)")

---

Tags

responsephpapiweblaravellibrarytraitformatformattingrespondresponse-format-trait

### Embed Badge

![Health badge](/badges/abdulbaset-response-format-trait/health.svg)

```
[![Health](https://phpackages.com/badges/abdulbaset-response-format-trait/health.svg)](https://phpackages.com/packages/abdulbaset-response-format-trait)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.8k3](/packages/defstudio-telegraph)[resend/resend-laravel

Resend for Laravel

1222.7M9](/packages/resend-resend-laravel)[api-platform/laravel

API Platform support for Laravel

58171.5k14](/packages/api-platform-laravel)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)[wayofdev/laravel-symfony-serializer

📦 Laravel wrapper around Symfony Serializer.

2117.7k](/packages/wayofdev-laravel-symfony-serializer)

PHPackages © 2026

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