jeevanjoshi / laravel-api-response
A simple and elegant API response formatter for Laravel
Package info
github.com/thecrazydiamond1/laravel-api-response
pkg:composer/jeevanjoshi/laravel-api-response
v1.0.0
2026-05-07 09:55 UTC
Requires
- php: ^8.1
- illuminate/http: ^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.0|^11.0
README
A simple and elegant API response formatter for Laravel.
Installation
composer require jeevanjoshi/laravel-api-response
The package will be auto-discovered by Laravel. No manual configuration needed.
Usage
use ApiResponse; // Success response (200) return ApiResponse::success($data, 'Users fetched'); // Created response (201) return ApiResponse::created($data, 'User created'); // Paginated response (200) return ApiResponse::paginated($users); // Error response (500) return ApiResponse::error('Something went wrong'); // Not found response (404) return ApiResponse::notFound('User not found'); // Unauthorized response (401) return ApiResponse::unauthorized(); // Forbidden response (403) return ApiResponse::forbidden(); // Validation error response (422) return ApiResponse::validation($errors); // No content response (200) return ApiResponse::noContent();
Response Structure
Success
{
"success": true,
"message": "Users fetched",
"data": {}
}
Error
{
"success": false,
"message": "Something went wrong",
"errors": null
}
Paginated
{
"success": true,
"message": "Success",
"data": [],
"meta": {
"current_page": 1,
"last_page": 5,
"per_page": 15,
"total": 75
}
}
Validation
{
"success": false,
"message": "Validation failed",
"errors": {
"email": ["The email field is required"]
}
}
License
MIT