laravel-api-response maintained by jeevanjoshi
Description
A simple and elegant API response formatter for Laravel
Author
Last update
2026/05/07 11:55
(dev-main)
License
Downloads
0
Laravel API Response
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