<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## laravel 內置默認支持宏擴展的類有哪些? * Response? ? ? ? ? ? ? ? ? ? ? ? ? 響應類 * Request? ? ? ? ? ? ? ? ? ? ? ? ? ? ?請求類 * Collection? ? ? ? ? ? ? ? ? ? ? ? ? ?數據集 * HTML? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?HTML擴展類 * Form? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 表單擴展類 * Filesystem? ? ? ? ? ? ? ? ? ? ? ? ?資源文件 * Cache? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 緩存操作類 * Str   ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?字符串操作類 * Arr? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?數組操作類 * Translator? ? ? ? ? ? ? ? ? ? ? ? ? 翻譯器(多語言版本開發) * Database-Builder? ? ? ? ? ? ? 數據庫連接操作類 * ... 我們在使用 laravel 來寫 API 時,經常需要返回一個 json 字符串或 JsonResponse,通常我們的做法可能有兩種。 1、在 BaseController 中定義一個返回 Json 響應 de 方法,然后繼承該 BaseController。如: ``` //BaseController.php public function json($data = null, $status = 200, $headers = [], $options = 0) { return new JsonResponse($data, $status, $headers, $options); } //YourController.php class YourController extends BaseController { public function users(UserRepository $userRepository) { return $this->json($userRepository->allUser()); } } ``` 然而這寫法確實挺方便,然而當你在其他地方需要使用到 Json 響應時(如中間件驗證失敗時你想要返回一個 Json 響應)。你無法使用到 $this->json(...)。 2、直接在需要用到 Json 響應得地方使用 return new JsonResponse 或者使用 Response Facade。 但這種做法當需要修改 Response 響應時得全部改動,不可取。 Response 宏 Laravel 提供了一個非常方便的響應宏來處理這一情況 首先,我們需要先注冊一個響應宏,在任意一個 ServiceProvider 的 boot 方法里(ResponseMacroServiceProvider),使用 Response Facade 注冊 ``` Response::macro('success', function ($data = [], $message = 'success') { return new JsonResponse([ 'code' => 0, 'data' => $data, 'message' => $message ], 200); }); ``` 接下來, 你可以再任何地方使用它 response()。 ``` public function users(UserRepository $userRepository) { return response()->success($userRepository->all(), 'success'); } ``` 原文地址:[https://learnku.com/articles/5139/laravel-response-macro-principle](https://learnku.com/articles/5139/laravel-response-macro-principle)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看