jeevanjoshi/laravel-api-response
最新稳定版本:v1.0.0
Composer 安装命令:
composer require jeevanjoshi/laravel-api-response
包简介
A simple and elegant API response formatter for Laravel
README 文档
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
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-07