{"id":485,"date":"2021-05-25T07:26:49","date_gmt":"2021-05-25T07:26:49","guid":{"rendered":"http:\/\/robinluo.top\/?p=485"},"modified":"2021-05-25T07:26:49","modified_gmt":"2021-05-25T07:26:49","slug":"laravel-%e5%85%a5%e5%8f%a3","status":"publish","type":"post","link":"https:\/\/robinluo.top\/?p=485","title":{"rendered":"laravel \u5165\u53e3"},"content":{"rendered":"\n<p>php \u901a\u8fc7 <a href=\"https:\/\/symfony.com\/doc\/current\/components\/http_foundation.html\">symfony\/http-foundation<\/a>\uff08http\u8bf7\u6c42\u54cd\u5e94\u5c01\u88c5\uff09 \u6846\u67b6\u6355\u83b7http\u8bf7\u6c42<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>laravel kernel \u7c7b \u4e3alaravel http \u5165\u53e3<\/p>\n\n\n\n<p>middleware \u7c7b\u4f3c\u4e8e \u8fc7\u6ee4\u5668 \u53ef\u4ee5\u6267\u884c\u8bf7\u6c42\u5904\u7406 \u7136\u540enext \u6267\u884c\u5904\u7406\u94fe \u5fc5\u5b9a\u6709 handle \u65b9\u6cd5 \u5f53\u9700\u8981\u5904\u7406\u8bf7\u6c42\u524d\u64cd\u4f5c \u5728\u8c03\u7528 $next \u524d\u4fee\u6539\u8bf7\u6c42\u4fe1\u606f  \u5f53\u9700\u8981\u5904\u7406\u8bf7\u6c42\u540e  \u6216\u8005 \u5728\u54cd\u5e94\u4e0a\u64cd\u4f5c  \u5219 \u5728$next\u540e \u4fee\u6539\u4fe1\u606f \u4e14\u8fd4\u56de\u7ed3\u679c\u5fc5\u5b9a\u4e3a $response\u5bf9\u8c61<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public function handle($request, Closure $next)\n    {\n        \/\/ Check if we're dealing with CORS and if we should handle it\n        if (! $this->shouldRun($request)) {\n            return $next($request);\n        }\n\n        \/\/ For Preflight, return the Preflight response\n        if ($this->cors->isPreflightRequest($request)) {\n            $response = $this->cors->handlePreflightRequest($request);\n\n            $this->cors->varyHeader($response, 'Access-Control-Request-Method');\n\n            return $response;\n        }\n\n        \/\/ Add the headers on the Request Handled event as fallback in case of exceptions\n        if (class_exists(RequestHandled::class) &amp;&amp; $this->container->bound('events')) {\n            $this->container->make('events')->listen(RequestHandled::class, function (RequestHandled $event) {\n                $this->addHeaders($event->request, $event->response);\n            });\n        }\n\n        \/\/ Handle the request\n        $response = $next($request);\n\n        if ($request->getMethod() === 'OPTIONS') {\n            $this->cors->varyHeader($response, 'Access-Control-Request-Method');\n        }\n\n        return $this->addHeaders($request, $response);\n    }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>php \u901a\u8fc7 symfony\/http-foundation\uff08http\u8bf7\u6c42\u54cd\u5e94\u5c01\u88c5\uff09 \u6846\u67b6\u6355\u83b7http\u8bf7\u6c42 laravel kernel \u7c7b \u4e3alaravel http \u5165\u53e3 middleware \u7c7b\u4f3c\u4e8e \u8fc7\u6ee4\u5668 \u53ef\u4ee5\u6267\u884c\u8bf7\u6c42\u5904\u7406 \u7136\u540enext \u6267\u884c\u5904\u7406\u94fe \u5fc5\u5b9a\u6709 handle \u65b9\u6cd5 \u5f53\u9700\u8981\u5904\u7406\u8bf7\u6c42\u524d\u64cd\u4f5c \u5728\u8c03\u7528 $next \u524d\u4fee\u6539\u8bf7\u6c42\u4fe1\u606f \u5f53\u9700\u8981\u5904\u7406\u8bf7\u6c42\u540e \u6216\u8005 \u5728\u54cd\u5e94\u4e0a\u64cd\u4f5c \u5219 \u5728$next\u540e \u4fee\u6539\u4fe1\u606f \u4e14\u8fd4\u56de\u7ed3\u679c\u5fc5\u5b9a\u4e3a $response\u5bf9\u8c61<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[10],"_links":{"self":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/485"}],"collection":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=485"}],"version-history":[{"count":9,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/485\/revisions"}],"predecessor-version":[{"id":494,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/485\/revisions\/494"}],"wp:attachment":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}