mzaman / laravel-api-response
There is no license information available for the latest version (dev-main) of this package.
A flexible and scalable API response handling package for Laravel
dev-main
2025-07-08 22:36 UTC
Requires
- php: ^7.3|^8.0|^8.1|^8.2|^8.3|^8.4
- illuminate/support: ^9.0
This package is auto-updated.
Last update: 2025-07-08 22:36:59 UTC
README
This package provides a flexible and scalable structure for handling API responses in Laravel. It includes support for custom API status codes, locale management, error handling, and response formatting.
Installation
You can install the package via Composer:
composer require mzaman/laravel-api-response
Usage
You can use helper functions to generate API responses:
Success Response
return api_response(['data' => 'Some data'], 'success', 200, 'Data fetched successfully');
Error Response
return api_error('An error occurred', 'error', 500, ['error' => 'Details of error']);
Exception Handling
The package supports custom exceptions. You can throw an ApiResponseException
and it will automatically be caught and formatted.
Localization
You can set a locale for each response:
return api_response(['data' => 'Some data'], 'success', 200, 'Success', null, 'en');
License
This package is open-sourced software licensed under the MIT license.