下面由laravel教程欄目給大家介紹如何把開發(fā)中常用class的整合成了一個包,避免每次重復(fù)復(fù)制粘貼的方法,希望對需要的朋友有所幫助!
laravel-quick
laravel-quick(github 地址:https://github.com/youyingxiang/laravel-quick.git) 封裝了一些我們開發(fā)中常見的工具,使開發(fā)變得更高效
主要包含翻譯了驗證的語言包提示根據(jù) symfony\\\\component\\\\httpfoundation\\\\response 為狀態(tài)碼的接口格式異常類處理集成基于 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;// 請求參數(shù)錯誤throw new apirequestexception();// 404 未找到throw new apinotfoundexception();// 系統(tǒng)錯誤throw new apisystemexception()// 未授權(quán)throw new apiunauthexception()自定義錯誤繼承yxx\\\\laravelquick\\\\exceptions自己參照對應(yīng)代碼自定義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 命令創(chuàng)建 trait php artisan quick:create-trait test創(chuàng)建 service php artisan quick:create-service test/testservice創(chuàng)建 repository php artisan quick:create-repository test
電腦無法使用搜索功能如何修復(fù)|電腦提示無法找到運行搜索的文件怎么辦云服務(wù)器硬盤怎么拆下來做本地云服務(wù)器網(wǎng)站SEO優(yōu)化排名波動大,是為什么呢?使用工具要么連接不到服務(wù)器域名引發(fā)權(quán)屬糾紛 法院一審駁回起訴企業(yè)云服務(wù)器租賃Chrome瀏覽器擴展推薦:如意淘