globalxtreme/response
最新稳定版本:2.0.5
Composer 安装命令:
composer require globalxtreme/response
包简介
GlobalXtreme Response Pattern
README 文档
README
Install with composer
To install with Composer, simply require the latest version of this package.
composer require globalxtreme/response
Using
- Install custom constant error/success and helpers with command.
php artisan globalxtreme:response-install
- Copy helpers file path app/Packages/Response/Status/globals.php to composer.json
{ "autoload": { "files": [ "app/Packages/Response/Status/globals.php" ] } } - You can add custom helpers function for error/success response in app/Packages/Response/Status/globals.php
use App\Packages\Response\Constant\Error; if (!function_exists("errTestingCustom")) { function errTestingCustom($internalMsg = "") { error(Error::DEFAULT, $internalMsg); } }
- Using response with controller.
use App\Http\Controllers\Controller; use App\Models\Custom; use GlobalXtreme\Parser\Parser; use GlobalXtreme\Response\Response; use GlobalXtreme\Response\Status; class CustomController extends Controller { public function testing() { // Get more than one data $customs = Custom::get(); // Display data auto call parser from Response package $results = success($customs); // Display data using parser class $result = success(Parser::get($customs)); // Get one data $custom = Custom::first(); // Display data auto call parser from Response package $result = success($custom); // Display data using parser class $result = success(Parser::first($custom)); // Get data with pagination $customs = Custom::paginate(10); // Display data auto call parser from Response package $results = success($customs); // Display data using parser class and manual process pagination $results = success(Parser::get($customs), pagination: pagination($customs)); // Display response using Response::class $status = new Status(true); // You can choose response type json/object $results = Response::json($status, $customs); $results = Response::object($status, $customs); } }
统计信息
- 总下载量: 256
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-22