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(1y ago)938MITPHPPHP ^8.0

Since Dec 23Pushed 1y 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 1mo ago

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

29

—

LowBetter than 60% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

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

702d 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

[resend/resend-laravel

Resend for Laravel

1191.4M6](/packages/resend-resend-laravel)[obiefy/api-response

Simple Laravel package to return Json responses.

17324.6k](/packages/obiefy-api-response)[dragon-code/laravel-json-response

Automatically always return a response in JSON format

1118.6k1](/packages/dragon-code-laravel-json-response)[vinelab/api-manager

Laravel API Manager Package - beatify and unify your responses with the least effort possible.

392.1k](/packages/vinelab-api-manager)

PHPackages © 2026

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