jooservices/laravel-controller
Composer 安装命令:
composer require jooservices/laravel-controller
包简介
Laravel API controller foundation for standardized JSON responses, pagination, status endpoints, trace IDs, and custom formatters.
关键字:
README 文档
README
JOOservices Laravel Controller is a Laravel API controller foundation for standardized JSON response envelopes, resource-friendly helpers, pagination metadata, status endpoints, trace IDs, and formatter-based response customization.
Composer package: jooservices/laravel-controller
Current release: 1.3.0
Features
- base API controller helpers for success, error, validation, status, and no-content responses
- Laravel
JsonResourceandResourceCollectionfriendly response helpers - standardized response envelope with configurable keys
- length-aware, cursor, and offset pagination helpers
- trace ID support through a configurable request header
- optional status endpoint with version, environment, maintenance, and health-check metadata
- custom
ResponseFormattercontract for teams that need a different top-level JSON shape - optional exception response helper for common Laravel exceptions
- read-only
php artisan laravel-controller:doctordiagnostics
Installation
composer require jooservices/laravel-controller
Publish Config
php artisan vendor:publish --provider="JOOservices\LaravelController\Providers\LaravelControllerServiceProvider" --tag="config"
Optional translations:
php artisan vendor:publish --provider="JOOservices\LaravelController\Providers\LaravelControllerServiceProvider" --tag="laravel-controller-lang"
Quick Start
Use the package at the controller boundary. Keep request validation, business logic, and persistence in your application layers:
<?php namespace App\Http\Controllers\Api\V1; use App\Http\Requests\UserIndexRequest; use App\Http\Resources\UserResource; use App\Services\UserService; use Illuminate\Http\JsonResponse; use JOOservices\LaravelController\Http\Controllers\BaseApiController; final class UserController extends BaseApiController { public function index(UserIndexRequest $request, UserService $users): JsonResponse { return $this->respondWithPagination( paginator: $users->paginate($request->validated()), resourceClass: UserResource::class, message: 'Users retrieved successfully.', ); } }
Standard Architecture Usage
Recommended flow:
Request -> Controller -> FormRequest -> Service -> Repository -> Model
Model / entity / data object -> Laravel Resource -> API response envelope -> JsonResponse
Laravel Resource remains the presentation transformer. JOOservices Laravel Controller wraps the transformed payload in the API response envelope.
Response Envelope Example
{
"success": true,
"code": 200,
"message": "Users retrieved successfully.",
"data": [],
"meta": {},
"errors": null,
"trace_id": "550e8400-e29b-41d4-a716-446655440000"
}
Resource Example
public function show(UserShowRequest $request, UserService $users): JsonResponse { return $this->respondWithResource( resource: new UserResource($users->findForDisplay($request->validated('id'))), message: 'User retrieved successfully.', ); }
DTOs, Arrayable, JsonSerializable, and objects with toArray() may be accepted as input data, but they do not replace Laravel Resources as the presentation layer.
Pagination Example
public function index(UserIndexRequest $request, UserService $users): JsonResponse { return $this->respondWithPagination( paginator: $users->paginate($request->validated()), resourceClass: UserResource::class, message: 'Users retrieved successfully.', ); }
Error Response Example
public function archive(UserArchiveRequest $request, UserService $users): JsonResponse { if (! $users->canArchive($request->validated('id'))) { return $this->respondWithError( message: 'User cannot be archived.', code: 409, errors: ['user' => ['The user has active dependencies.']], ); } $users->archive($request->validated('id')); return $this->respondNoContent(); }
Status Endpoint
When package routes are enabled, the status endpoint is available under the configured prefix:
GET /api/v1/status
Run diagnostics from the CLI:
php artisan laravel-controller:doctor php artisan laravel-controller:doctor --json
Custom Formatter
<?php namespace App\Support; use JOOservices\LaravelController\Contracts\ResponseFormatter; final class ApiResponseFormatter implements ResponseFormatter { public function format(array $response): array { return [ 'ok' => $response['success'], 'status' => $response['code'], 'message' => $response['message'], 'payload' => $response['data'], 'error' => $response['errors'], 'request_id' => $response['trace_id'], ]; } }
Configuration
Important config keys:
response_formatterkeystrace_id.headeruse_translationsenvelope_204success_codesvalidation.messageroutes.enabledroutes.prefixroutes.auto_map_host_routesstatuspagination_linksitem_links
Current Limitations And Non-Goals
This package is:
- base API controller helpers
- standard response envelope helpers
- pagination and status response helpers
- formatter contract
- optional exception response helper
This package is not:
- CRUD generator
- service layer replacement
- repository replacement
- validation package
- full application exception-handler framework
- JSON:API full implementation
- business logic layer
Documentation
- Documentation Hub
- Architecture
- Getting Started
- User Guide
- Examples
- Development
- Release Process
- Maintenance
AI Contributor Support
Development Commands
composer lint
composer lint:all
composer lint:fix
composer test
composer test:coverage
composer check
composer ci
Security And Contributing
Use GitHub issues for bug reports and security coordination unless a dedicated security policy is added.
License
JOOservices Laravel Controller is open-sourced software licensed under the MIT license.
jooservices/laravel-controller 适用场景与选型建议
jooservices/laravel-controller 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 76 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「pagination」 「controller」 「formatter」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jooservices/laravel-controller 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jooservices/laravel-controller 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jooservices/laravel-controller 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Provides a Data Grid tables for your Symfony project.
Normalize an index range from user input
Display page number links in Twig or PHP templates.
Alfabank REST API integration
Symfony package for pagination, sorting and filtering of a list items.
统计信息
- 总下载量: 76
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-14