溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何把laravel開發(fā)中常用class的整合成一個包

發(fā)布時間:2021-03-10 15:32:42 來源:億速云 閱讀:184 作者:小新 欄目:編程語言

這篇文章給大家分享的是有關如何把laravel開發(fā)中常用class的整合成一個包的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

laravel-quick

laravel-quick(github 地址:https://github.com/youyingxiang/laravel-quick.git) 封裝了一些我們開發(fā)中常見的工具,使開發(fā)變得更高效

  • 主要包含翻譯了驗證的語言包提示

  • 根據 Symfony\Component\HttpFoundation\Response 為狀態(tài)碼的接口格式

  • 異常類處理

  • 集成基于 redis 的各種緩存操作

  • service,repository,trait的 artisan 命令生成;

安裝

  • composer require yxx/laravel-quick

  • linux 和 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()// 未授權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 命令

  • 創(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

感謝各位的閱讀!關于“如何把laravel開發(fā)中常用class的整合成一個包”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI