下面由Laravel教程栏目给大家介绍如何把开发中常用class的整合成了一个包,避免每次重复复制粘贴的方法,希望对需要的朋友有所帮助!
laravel-quick(github 地址:https://github.com/youyingxiang/laravel-quick.git) 封装了一些我们开发中常见的工具,使开发变得更高效
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里面的方法....
以上就是把laravel开发中常用class的整合成一个包,避免每次重复复制粘贴的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号