這篇文章給大家分享的是有關(guān)如何把laravel開(kāi)發(fā)中常用class的整合成一個(gè)包的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
laravel-quick(github 地址:https://github.com/youyingxiang/laravel-quick.git) 封裝了一些我們開(kāi)發(fā)中常見(jiàn)的工具,使開(kāi)發(fā)變得更高效
主要包含翻譯了驗(yàn)證的語(yǔ)言包提示
根據(jù) Symfony\Component\HttpFoundation\Response 為狀態(tài)碼的接口格式
異常類(lèi)處理
集成基于 redis 的各種緩存操作
service,repository,trait的 artisan 命令生成;
composer require yxx/laravel-quick
linux 和 macphp artisan vendor:publish --provider="Yxx\\LaravelQuick\\LaravelQuickServiceProvider"
windowsphp artisan vendor:publish --provider="Yxx\LaravelQuick\LaravelQuickServiceProvider"
異常使用例子
use Yxx\LaravelQuick\Exceptions\Api\ApiNotFoundException;// 請(qǐng)求參數(shù)錯(cuò)誤throw new ApiRequestException();// 404 未找到throw new ApiNotFoundException();// 系統(tǒng)錯(cuò)誤throw new ApiSystemException()// 未授權(quán)throw new ApiUnAuthException()自定義錯(cuò)誤繼承Yxx\LaravelQuick\Exceptions自己參照對(duì)應(yīng)代碼自定義
api 接口使用
use Yxx\LaravelQuick\Traits\JsonResponseTrait// 成功return $this->success("消息",['name'=>"張三"]);// 失敗return $this->error("錯(cuò)誤");// 自定義return $this->apiResponse(Response::HTTP_BAD_GATEWAY,"502錯(cuò)誤");
緩存的使用(封裝了 redis 的一些方法)
use Yxx\LaravelQuick\Facades\CacheClient;CacheClient::hSet("test","1","張三");CacheClient::hGet("test","1");CacheClient::lPush("test","1");具體參考Yxx\LaravelQuick\Services\CacheService里面的方法....
創(chuàng)建 Traitphp artisan quick:create-trait test
創(chuàng)建 Service php artisan quick:create-service Test/TestService
創(chuàng)建 Repositoryphp artisan quick:create-repository Test
感謝各位的閱讀!關(guān)于“如何把laravel開(kāi)發(fā)中常用class的整合成一個(gè)包”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
本文名稱(chēng):如何把laravel開(kāi)發(fā)中常用class的整合成一個(gè)包-創(chuàng)新互聯(lián)
文章出自:http://www.chinadenli.net/article6/dhcpog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、服務(wù)器托管、網(wǎng)站制作、虛擬主機(jī)、Google、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容