把laravel开发中常用class的整合成一个包,避免每次重复复制粘贴

发布时间:2025-05-10 点击:29
下面由laravel教程栏目给大家介绍如何把开发中常用class的整合成了一个包,避免每次重复复制粘贴的方法,希望对需要的朋友有所帮助!
laravel-quick
laravel-quick(github 地址:https://github.com/youyingxiang/laravel-quick.git) 封装了一些我们开发中常见的工具,使开发变得更高效
主要包含翻译了验证的语言包提示根据 symfony\\\\component\\\\httpfoundation\\\\response 为状态码的接口格式异常类处理集成基于 redis 的各种缓存操作service,repository,trait的 artisan 命令生成;安装composer require yxx/laravel-quicklinux 和 mac
php artisan vendor:publish --provider="yxx\\\\\\\\laravelquick\\\\\\\\laravelquickserviceprovider"windows
php artisan vendor:publish --provider="yxx\\\\laravelquick\\\\laravelquickserviceprovider"怎么使用异常使用例子
use yxx\\\\laravelquick\\\\exceptions\\\\api\\\\apinotfoundexception;// 请求参数错误throw new apirequestexception();// 404 未找到throw new apinotfoundexception();// 系统错误throw new apisystemexception()// 未授权throw new apiunauthexception()自定义错误继承yxx\\\\laravelquick\\\\exceptions自己参照对应代码自定义api 接口使用
use yxx\\\\laravelquick\\\\traits\\\\jsonresponsetrait// 成功return $this->success("消息",['name'=>"张三"]);// 失败return $this->error("错误");// 自定义return $this->apiresponse(response::http_bad_gateway,"502错误");缓存的使用(封装了 redis 的一些方法)
use yxx\\\\laravelquick\\\\facades\\\\cacheclient;cacheclient::hset("test","1","张三");cacheclient::hget("test","1");cacheclient::lpush("test","1");具体参考yxx\\\\laravelquick\\\\services\\\\cacheservice里面的方法....artisan 命令创建 trait php artisan quick:create-trait test创建 service php artisan quick:create-service test/testservice创建 repository php artisan quick:create-repository test

电脑无法使用搜索功能如何修复|电脑提示无法找到运行搜索的文件怎么办
云服务器硬盘怎么拆下来
做本地云服务器
网站SEO优化排名波动大,是为什么呢?
使用工具要么连接不到服务器
域名引发权属纠纷 法院一审驳回起诉
企业云服务器租赁
Chrome浏览器扩展推荐:如意淘