{"id":4728,"date":"2022-12-25T09:22:04","date_gmt":"2022-12-25T00:22:04","guid":{"rendered":"https:\/\/www.wetch.co.jp\/?p=4728"},"modified":"2022-12-25T09:22:06","modified_gmt":"2022-12-25T00:22:06","slug":"laravel%ef%bc%9a%e3%83%a1%e3%83%b3%e3%83%86%e3%83%8a%e3%83%b3%e3%82%b9%e3%83%a2%e3%83%bc%e3%83%89","status":"publish","type":"post","link":"https:\/\/www.wetch.co.jp\/note\/laravel%ef%bc%9a%e3%83%a1%e3%83%b3%e3%83%86%e3%83%8a%e3%83%b3%e3%82%b9%e3%83%a2%e3%83%bc%e3%83%89\/","title":{"rendered":"Laravel\uff1a\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\uff08Laravel\uff09\u306e\u66f4\u65b0\u4f5c\u696d\u4e2d\u306f\u30a2\u30af\u30bb\u30b9\u3092\u62d2\u7d76\u3057\u305f\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<br>Web\u30b5\u30fc\u30d0\u30a2\u30d7\u30ea\uff08Apache\u7b49\uff09\u3092\u6b62\u3081\u3066\u3057\u307e\u3046\u3068\u3044\u3046\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u304c\u3001Laravel\u3067\u306f\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u72b6\u614b\u3092\u30bd\u30d5\u30c8\u7684\u306b\u5b9f\u73fe\u3059\u308b\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u3092\u958b\u59cb\u3059\u308b\u65b9\u6cd5\u306f\u7c21\u5358\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan down<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u3092\u89e3\u9664\u3059\u308b\u30b3\u30de\u30f3\u30c9\u306f\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan up<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u3067\u306f\u5168\u3066\u306e\u30a2\u30af\u30bb\u30b9\u306b\u5bfe\u3057\u3066HTTP\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9\u3068\u3057\u3066503\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<br>503\u306f\u300cService Unavailable\uff08\u30b5\u30fc\u30d3\u30b9\u304c\u4e00\u6642\u7684\u306b\u904e\u8ca0\u8377\u3084\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u3067\u4f7f\u7528\u4e0d\u53ef\u80fd\uff09\u300d\u3068\u3044\u3046\u610f\u5473\u306a\u306e\u3067\u7d0d\u5f97\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f0a\u793e\u3067\u306f\u6628\u4eca\u306f\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3068\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306e\u5206\u96e2\u3092\u9032\u3081\u3066\u304a\u308a\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u306fNuxt\u3067\u5b9f\u88c5\u3001\u4e21\u8005\u306e\u9593\u306fAPI\u3067\u63a5\u7d9a\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<br>\u3053\u306e\u3088\u3046\u306a\u30b1\u30fc\u30b9\u3067\u3082\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u306f\u6709\u52b9\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u3048\u3070\u3001API\u306b\u304a\u3044\u3066\u300capi\/test\u300d\u306a\u308b\u30a2\u30af\u30b7\u30e7\u30f3\u304c\u5b58\u5728\u3059\u308b\u3068\u3057\u307e\u3059\u3002<br>\u300croutes\/api.php\u300d\u306e\u5185\u5bb9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Route::get('test', \\App\\Http\\Controllers\\TestController::class)-&gt;name('test');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u30a2\u30af\u30b7\u30e7\u30f3\u306b\u5bfe\u3057\u3066\u4ee5\u4e0b\u306e\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u304c\u6210\u7acb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$path = route('test');\n\n$response = $this-&gt;json('get', $path);\n$response-&gt;assertStatus(200);\n\n$this-&gt;artisan('down'); \/\/ \u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u958b\u59cb\n\n$response = $this-&gt;json('get', $path);\n$response-&gt;assertStatus(503);\n\n$this-&gt;artisan('up'); \/\/ \u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u89e3\u9664\n\n$response = $this-&gt;json('get', $path);\n$response-&gt;assertStatus(200);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u306a\u304a\u3001\u7279\u5b9a\u306e\u30ad\u30fc\u30ef\u30fc\u30c9\uff08\u30d0\u30a4\u30d1\u30b9\u30c8\u30fc\u30af\u30f3\uff09\u3092\u6307\u5b9a\u3057\u305f\u5834\u5408\u306f\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u3067\u3082\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306e\u6a5f\u80fd\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5177\u4f53\u7684\u306b\u306f\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u958b\u59cb\u6642\u306b\u30d0\u30a4\u30d1\u30b9\u30c8\u30fc\u30af\u30f3\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan down --secret=\"hogehoge\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u300c&#8211;secret\u300d\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u6307\u5b9a\u3057\u3066\u3044\u308b\u306e\u304c\u30d0\u30a4\u30d1\u30b9\u30c8\u30fc\u30af\u30f3\uff08\u3053\u306e\u5834\u5408\u306f\u300chogehoge\u300d\uff09\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u306e\u30c8\u30fc\u30af\u30f3\u3092\u6307\u5b9a\u3057\u3066\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u306e\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u4e00\u65e6\u5f53\u8a72\u30c9\u30e1\u30a4\u30f3\u306b\u30d0\u30a4\u30d1\u30b9\u30c8\u30fc\u30af\u30f3\u3092\u6307\u5b9a\u3057\u3066\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002<br>\u3053\u306e\u6642\u3001\u30d0\u30a4\u30d1\u30b9\u30af\u30c3\u30ad\u30fc\uff08laravel_maintenance\uff09\u304c\u8a2d\u5b9a\u3055\u308c\u308b\u305f\u3081\u3001\u4ee5\u964d\u540c\u30af\u30c3\u30ad\u30fc\u304c\u8a2d\u5b9a\u3055\u308c\u305f\u72b6\u614b\u3067\u3042\u308c\u3070\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u3092\u30d0\u30a4\u30d1\u30b9\u3057\u3066\u5404\u7a2e\u6a5f\u80fd\u304c\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u3061\u3089\u3082\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u3067\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$path = route('test');\n\n\/\/ \u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u958b\u59cb\uff08\u30d0\u30a4\u30d1\u30b9\u30c8\u30fc\u30af\u30f3\u3042\u308a\uff09\n$this-&gt;artisan('down', &#91;'--secret' =&gt; 'hogehoge']);\n\n$response = $this-&gt;json('get', $path);\n$response-&gt;assertStatus(503);\n\n$response = $this-&gt;get('\/hogehoge'); \/\/ \u30d0\u30a4\u30d1\u30b9\u30c8\u30fc\u30af\u30f3\u6307\u5b9a\n$response-&gt;assertStatus(302);\n\n\/\/ \u30d0\u30a4\u30d1\u30b9\u30af\u30c3\u30ad\u30fc\uff08laravel_maintenance\uff09\u53d6\u5f97\n$cookieObjects = $response-&gt;headers-&gt;getCookies();\nforeach ($cookieObjects as $cookieObject) {\n    if ($cookieObject-&gt;getName() === 'laravel_maintenance') {\n        $laravelMaintenanceVal = $cookieObject-&gt;getValue();\n    }\n}\n\n$this-&gt;disableCookieEncryption();\n$this-&gt;withCredentials();\n$this-&gt;withCookies(&#91;'laravel_maintenance' =&gt; $laravelMaintenanceVal]);\n$response = $this-&gt;json('get', $path);\n$response-&gt;assertStatus(200);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5927\u96d1\u628a\u306b\u8aac\u660e\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u6d41\u308c\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6700\u521d\u306b\u30d0\u30a4\u30d1\u30b9\u30c8\u30fc\u30af\u30f3\u3092\u6307\u5b9a\u3057\u3066\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u3092\u958b\u59cb<\/li>\n\n\n\n<li>$path\u3078\u306e\u30a2\u30af\u30bb\u30b9\u304c503\u3067\u30a8\u30e9\u30fc\u3068\u306a\u308b\u3053\u3068\u3092\u78ba\u8a8d<\/li>\n\n\n\n<li>\u30d0\u30a4\u30d1\u30b9\u30c8\u30fc\u30af\u30f3\u3092\u6307\u5b9a\u3057\u3066\u30a2\u30af\u30bb\u30b9<\/li>\n\n\n\n<li>\u30d0\u30a4\u30d1\u30b9\u30af\u30c3\u30ad\u30fc\u3092\u53d6\u5f97<\/li>\n\n\n\n<li>\u30d0\u30a4\u30d1\u30b9\u30af\u30c3\u30ad\u30fc\u3092\u6307\u5b9a\u3057\u305f$path\u3078\u306e\u30a2\u30af\u30bb\u30b9\u304c\u6b63\u5e38\u7d42\u4e86\u3059\u308b\u3053\u3068\u3092\u78ba\u8a8d<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u306f\u6210\u7acb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u30b3\u30de\u30f3\u30c9\u4e00\u767a\u3067\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u3092\u958b\u59cb\u3057\u305f\u308a\u89e3\u9664\u3057\u305f\u308a\u3067\u304d\u308b\u306e\u306f\u4fbf\u5229\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\uff08\u4ee5\u4e0b\u3001\u86c7\u8db3\u306a\u304c\u3089\uff09<br>\u5b9f\u306f\u3001\u4e0a\u8a18\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u306b\u304a\u3044\u3066\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u304b\u3089\u623b\u3055\u308c\u305f\u30af\u30c3\u30ad\u30fc\u3092\u6307\u5b9a\u3057\u3066\u6240\u5b9a\u306eAPI\u3092\u547c\u3073\u51fa\u3059\u51e6\u7406\u306e\u5b9f\u73fe\u306b\u610f\u5916\u306b\u82e6\u6226\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u307e\u305a\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u60c5\u5831\u304b\u3089\u30af\u30c3\u30ad\u30fc\u306e\u5024\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u306b\u95a2\u3059\u308b\u60c5\u5831\u304c\u30cd\u30c3\u30c8\u4e0a\u3067\u3082\u3042\u307e\u308a\u898b\u5f53\u305f\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002<br>\u308f\u305a\u304b\u306a\u60c5\u5831\u3068\u8a66\u884c\u932f\u8aa4\u3067\u4e0a\u8a18\u306e\u3088\u3046\u306a\u3084\u308a\u65b9\u3067\u53d6\u5f97\u3067\u304d\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u304c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u307e\u305f\u3001\u53d6\u5f97\u3057\u305f\u30af\u30c3\u30ad\u30fc\u3092json\u30e1\u30bd\u30c3\u30c9\u3067\u306e\u30a2\u30af\u30b7\u30e7\u30f3\u547c\u3073\u51fa\u3057\u6642\u306b\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u3082\u8b0e\u3067\u3057\u305f\u3002<br>\u30af\u30c3\u30ad\u30fc\u3092\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u3067\u3042\u308b\u300cwithCookies\u300d\u306b\u95a2\u3059\u308b\u60c5\u5831\u306f\u30cd\u30c3\u30c8\u4e0a\u306b\u3082\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u3060\u3051\u3060\u3068\u6b63\u3057\u304f\u52d5\u4f5c\u3057\u307e\u305b\u3093\u3002<br>\u5b9f\u306fjson\u30e1\u30bd\u30c3\u30c9\u3067\u306f\u300cwithCredentials\u300d\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304a\u304b\u306a\u3044\u3068\u30af\u30c3\u30ad\u30fc\u304c\u6709\u52b9\u306b\u306a\u308a\u307e\u305b\u3093\u3002<br>\u52a0\u3048\u3066\u30af\u30c3\u30ad\u30fc\u306f\uff08\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306e\u8a2d\u5b9a\u6b21\u7b2c\u3067\u3059\u304c\uff09\u4e00\u822c\u7684\u306b\u306f\u6697\u53f7\u5316\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u30d0\u30a4\u30d1\u30b9\u30c8\u30fc\u30af\u30f3\u306b\u95a2\u3057\u3066\u306f\u6697\u53f7\u5316\u3055\u308c\u3066\u3044\u306a\u3044\u3053\u3068\u304c\u671f\u5f85\u3055\u308c\u308b\u6a21\u69d8\u3067\u3001\u6697\u53f7\u5316\u3092\u89e3\u9664\u3057\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u3092\u884c\u3063\u3066\u3044\u308b\u306e\u304c\u300cdisableCookieEncryption\u300d\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u306e\u3088\u3046\u306a\u64cd\u4f5c\u3092\u884c\u3046\u3053\u3068\u3067\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u304b\u3089\u623b\u3055\u308c\u305f\u30af\u30c3\u30ad\u30fc\u3092\u6307\u5b9a\u3057\u3066json\u30e1\u30bd\u30c3\u30c9\u306e\u5b9f\u884c\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u3089\u306b\u95a2\u3057\u3066\u8aac\u660e\u3055\u308c\u3066\u3044\u308b\u8a18\u4e8b\u3092\u30cd\u30c3\u30c8\u4e0a\u3067\u306f\u767a\u898b\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002<br>\u3053\u306e\u3088\u3046\u306a\u4f7f\u3044\u65b9\u306f\u3042\u307e\u308a\u3055\u308c\u306a\u3044\u3093\u3067\u3057\u3087\u3046\u304b\u306d\uff1f\uff08\u3042\u308b\u3044\u306f\u63a2\u3057\u65b9\u304c\u60aa\u3044\u306e\u304b\uff1f\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\uff08Laravel\uff09\u306e\u66f4\u65b0\u4f5c\u696d\u4e2d\u306f\u30a2\u30af\u30bb\u30b9\u3092\u62d2\u7d76\u3057\u305f\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002Web\u30b5\u30fc\u30d0\u30a2\u30d7\u30ea\uff08Apache\u7b49\uff09\u3092\u6b62\u3081\u3066\u3057\u307e\u3046\u3068\u3044\u3046\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u304c\u3001Laravel\u3067\u306f\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u72b6\u614b\u3092\u30bd\u30d5\u30c8\u7684\u306b\u5b9f\u73fe\u3059\u308b\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9 [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":4729,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[210],"tags":[],"class_list":["post-4728","post","type-post","status-publish","format-standard","has-post-thumbnail","category-210"],"_links":{"self":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/posts\/4728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/comments?post=4728"}],"version-history":[{"count":0,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/posts\/4728\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/media\/4729"}],"wp:attachment":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/media?parent=4728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/categories?post=4728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/tags?post=4728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}