Download the PHP package abdulbaset/response-format-trait without Composer
On this page you can find all versions of the php package abdulbaset/response-format-trait. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download abdulbaset/response-format-trait
More information about abdulbaset/response-format-trait
Files in abdulbaset/response-format-trait
Package response-format-trait
Short Description A PHP package for standardizing and formatting API and web responses.
License MIT
Homepage https://digitalatum.com
Informations about the package response-format-trait
Documentation
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
- Standardized API and web response formatting.
- Predefined HTTP status codes with detailed messages.
- Easy integration into Laravel projects.
Installation
Use Composer to install the package:
You can install this package via Composer:
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:
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
- Publishing Configuration File You can publish the configuration file or language files using the following command:
This command will copy the response-format.php
file to your config directory, allowing you to customize the package's behavior.
- Generating Responses
-
First example
-
The second example This will generate a JSON response with the provided status code, message, details, and optional data.
- Checks if a given language is supported
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
Here are some examples of how you can use the Respond
trait in your controllers:
- here you can customize message and details response as you need. and you will get the response like:
- here you can change the default language to get message and details for some specific local as you need. and you will get the response like: other example for 404 not found error and you will get the response like:
- if you want set the dynamically local language you can make middleware and set inside
config(['response-format.language' => config('app.local', 'en')]);
and you will get the response like: - if you want check the package is supported the language or not, you can use this
Respond::isLanguageSupported($language)
static method.
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
The package was created by Abdulbaset R. Sayed [email protected]
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
This Package is licensed under the MIT License - see the LICENSE file for details.
All versions of response-format-trait with dependencies
illuminate/support Version ^8.0|^9.0|^10.0
illuminate/http Version ^8.0|^9.0|^10.0