下面由Laravel教程栏目给大家介绍如何把开发中常用class的整合成了一个包,避免每次重复复制粘贴的方法,希望对需要的朋友有所帮助!
laravel-quick(github 地址:https://github.com/youyingxiang/laravel-quick.git) 封装了一些我们开发中常见的工具,使开发变得更高效
composer require yxx/laravel-quickphp artisan vendor:publish --provider="YxxLaravelQuickLaravelQuickServiceProvider"php artisan vendor:publish --provider="YxxLaravelQuickLaravelQuickServiceProvider"use YxxLaravelQuickExceptionsApiApiNotFoundException;// 请求参数错误throw new ApiRequestException();// 404 未找到throw new ApiNotFoundException();// 系统错误throw new ApiSystemException()// 未授权throw new ApiUnAuthException()自定义错误继承YxxLaravelQuickExceptions自己参照对应代码自定义
use YxxLaravelQuickTraitsJsonResponseTrait// 成功return $this->success("消息",['name'=>"张三"]);// 失败return $this->error("错误");// 自定义return $this->apiResponse(Response::HTTP_BAD_GATEWAY,"502错误");use YxxLaravelQuickFacadesCacheClient;CacheClient::hSet("test","1","张三");CacheClient::hGet("test","1");CacheClient::lPush("test","1");具体参考YxxLaravelQuickServicesCacheService里面的方法....php artisan quick:create-trait testphp artisan quick:create-service Test/TestServicephp artisan quick:create-repository Test