{"id":956,"date":"2023-09-17T15:41:33","date_gmt":"2023-09-17T06:41:33","guid":{"rendered":"https:\/\/shinke1987.net\/?p=956"},"modified":"2023-09-17T15:41:33","modified_gmt":"2023-09-17T06:41:33","slug":"laravel%e3%81%a7%e3%81%ae%e3%82%bb%e3%83%83%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"https:\/\/shinke1987.net\/?p=956","title":{"rendered":"Laravel\u3067\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u306b\u3064\u3044\u3066"},"content":{"rendered":"\n<h2 id=\"toc0\" class=\"wp-block-heading\">\u6982\u8981<\/h2>\n\n\n\n<p>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306f config\/session.php \u306b\u4fdd\u5b58\u3055\u308c\u3066\u3044\u308b\u3002<br>\u30bb\u30c3\u30b7\u30e7\u30f3\u306e\u4fdd\u5b58\u5148\u3092\u9078\u629e\u3067\u304d\u308b\u3002\u9078\u629e\u80a2\u306f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u53c2\u7167\u3059\u308b\u3068\u826f\u3044\u3002<\/p>\n\n\n\n<p>\u30bb\u30c3\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u3092\u64cd\u4f5c\u3059\u308b\u4e3b\u306a\u65b9\u6cd5\u306f\u3001<br>session\u30d8\u30eb\u30d1\u3068Request\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e2\u3064\u3002<\/p>\n\n\n\n<p>\u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u4f7f\u3046\u6642\u306b\u3001Request\u30af\u30e9\u30b9\u3092\u4f7f\u3063\u3066\u3082\u3001session\u30d8\u30eb\u30d1\u3092\u4f7f\u3063\u3066\u3082\u5b9f\u8df5\u7684\u306a\u9055\u3044\u306f\u307b\u307c\u7121\u3044\u3002<\/p>\n\n\n\n<p>Illuminate\\Http\\Request \u30af\u30e9\u30b9\u306e\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u306f\u3001<a href=\"https:\/\/laravel.com\/api\/10.x\/Illuminate\/Http\/Request.html\">https:\/\/laravel.com\/api\/10.x\/Illuminate\/Http\/Request.html<\/a><\/p>\n\n\n\n<h2 id=\"toc1\" class=\"wp-block-heading\">\u30bb\u30c3\u30b7\u30e7\u30f3\u30c9\u30e9\u30a4\u30d0\u304cdatabase\u306e\u5834\u5408<\/h2>\n\n\n\n<h3 id=\"toc2\" class=\"wp-block-heading\">last_activity\u306b\u65e5\u6642\u304c\u4fdd\u5b58\u3055\u308c\u308b<\/h3>\n\n\n\n<p>unix\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u3067\u4fdd\u5b58\u3055\u308c\u308b\u306e\u3067\u3001\u78ba\u8a8d\u3059\u308b\u306b\u306f\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u826f\u3044\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n(Linux\u306e\u30b7\u30a7\u30eb\u3067)\n$ date -d @last_activity\u306e\u6587\u5b57\u5217\n<\/pre><\/div>\n\n\n<h3 id=\"toc3\" class=\"wp-block-heading\">payload\u306b\u30bb\u30c3\u30b7\u30e7\u30f3\u60c5\u5831\u304c\u4fdd\u5b58\u3055\u308c\u308b<\/h3>\n\n\n\n<p>payload\u306fbase64\u3067\u30a8\u30f3\u30b3\u30fc\u30c9\u3055\u308c\u305f\u6587\u5b57\u5217\u304c\u5165\u3063\u3066\u3044\u308b\u306e\u3067\u3001<br>\u5185\u5bb9\u3092\u78ba\u8a8d\u3057\u305f\u3051\u308c\u3070\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u826f\u3044\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n(Tinker\u306a\u3069\u3067)\n&gt; base64_decode(&#039;payload\u306e\u6587\u5b57\u5217&#039;);\n<\/pre><\/div>\n\n\n<h2 id=\"toc4\" class=\"wp-block-heading\">Request\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304b\u3089\u64cd\u4f5c\u3059\u308b\u5834\u5408\u306e\u66f8\u5f0f<\/h2>\n\n\n\n<p>key\u304c\u3042\u308c\u3070\u5024\u3092\u53d6\u5f97\u3057\u3001key\u304c\u5b58\u5728\u3057\u306a\u304b\u3063\u305f\u5834\u5408\u3001default\u3092\u53d6\u5f97\u3059\u308b\u3002<br>default\u90e8\u5206\u306b\u30af\u30ed\u30fc\u30b8\u30e3\u3092\u6e21\u3059\u3053\u3068\u3082\u3067\u304d\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$request -&gt; session() -&gt; get(&#039;key&#039;, &#039;default&#039;);\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/\/ \u65e2\u5b58\u306e\u30ad\u30fc\u306b\u65b0\u3057\u3044\u5024\u3092\u8ffd\u52a0\uff08\u5024\u304c\u914d\u5217\u306b\u306a\u308b\uff09\n$request -&gt; session() -&gt; push(&#039;key&#039;, &#039;value&#039;);\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/\/ \u65e2\u5b58\u306e\u30ad\u30fc\u304b\u3089\u5024\u3092\u53d6\u5f97\u3057\u3001\u30ad\u30fc\u3068\u5024\u306e\u30bb\u30c3\u30c8\u3092\u524a\u9664\u3059\u308b\u3002\n$value = $request -&gt; session() -&gt; pull(&#039;key&#039;, &#039;default&#039;);\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/\/ \u30d5\u30a9\u30fc\u30e0\u306e\u5165\u529b\u3084\u308a\u76f4\u3057\u306a\u3069\u3067\u4f7f\u3048\u308b\u3002\n$request -&gt; session() -&gt; flash(&#039;key&#039;, &#039;value&#039;);\n\/\/ flash\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30bb\u30c3\u30b7\u30e7\u30f3\u306b\u4fdd\u5b58\u3055\u308c\u305f\u30c7\u30fc\u30bf\u306f\u3001\n\/\/ \u5373\u6642\u304a\u3088\u3073\u5f8c\u7d9a\u306eHTTP\u30ea\u30af\u30a8\u30b9\u30c8\u4e2d\u306b\u5229\u7528\u53ef\u80fd\u3002\n\/\/ \u5f8c\u7d9a\u306eHTTP\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u5f8c\u3001\u4e00\u6642\u4fdd\u5b58\u3057\u305f\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3059\u308b\u3002\n\n\/\/ \u8907\u6570\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u9593\u3001\n\/\/ \u4e00\u6642\u4fdd\u5b58\u30c7\u30fc\u30bf\u3092\u4fdd\u6301\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u3002\n$request -&gt; session() -&gt; reflash();\n\n\/\/ reflash\u30e1\u30bd\u30c3\u30c9\u3068\u306f\u9055\u3044\u3001\u7279\u5b9a\u306e\u30c7\u30fc\u30bf\u306e\u307f\u3092\u4fdd\u6301\u3059\u308b\u5834\u5408\u3002\n$request -&gt; session() -&gt; keep(&#x5B;&#039;key&#039;, &#039;value&#039;]);\n\n\/\/ \u4e00\u6642\u4fdd\u5b58\u30c7\u30fc\u30bf\u3092\u73fe\u5728\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306b\u5bfe\u3057\u3066\u306e\u307f\u4fdd\u6301\u3059\u308b\u5834\u5408\u3002\n$request -&gt; session() -&gt; now(&#039;key&#039;, &#039;value&#039;);\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/\/ 1\u3064\u306e\u30ad\u30fc\u3092\u524a\u9664\u3002\n$requst -&gt; session() -&gt; forget(&#039;key);\n\n\/\/ \u8907\u6570\u306e\u30ad\u30fc\u3092\u524a\u9664\u3002\n$request -&gt; session() -&gt; forget(&#x5B;&#039;key1&#039;, &#039;key2&#039;]);\n\n\/\/ \u5168\u3066\u306e\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3002\n$request -&gt; session() -&gt; flush();\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3ID\u306e\u518d\u751f\u6210\u3002\uff08\u30bb\u30c3\u30b7\u30e7\u30f3\u56fa\u5b9a\u653b\u6483\u5bfe\u7b56\uff09\n$request -&gt; session() -&gt; regenerate();\n\n\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3ID\u3092\u518d\u751f\u6210\u3057\u3066\u3001\u5168\u3066\u306e\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3002\n$request -&gt; session() -&gt; invalidate();\n<\/pre><\/div>\n\n\n<h3 id=\"toc5\" class=\"wp-block-heading\">\u899a\u3048\u66f8\u304d<\/h3>\n\n\n\n<p>has\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3059\u308b\u3068\u3001\u30ad\u30fc\u304c\u5b58\u5728\u3057\u3001\u5024\u304cnull\u3067\u306a\u3044\u5834\u5408\u306btrue\u3092\u8fd4\u3059\u3002<\/p>\n\n\n\n<p>exists\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3059\u308b\u3068\u3001\u30ad\u30fc\u304c\u5b58\u5728\u3059\u308c\u3070true\u3092\u8fd4\u3059\u3002<\/p>\n\n\n\n<p>missing\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3059\u308b\u3068\u3001\u30ad\u30fc\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306btrue\u3092\u8fd4\u3059\u3002<\/p>\n\n\n\n<h2 id=\"toc6\" class=\"wp-block-heading\">session\u30d8\u30eb\u30d1\u3092\u5229\u7528\u3057\u3066\u64cd\u4f5c\u3059\u308b\u5834\u5408\u306e\u66f8\u5f0f<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u304b\u3089\u30c7\u30fc\u30bf\u53d6\u5f97\u3002\n$value = session(&#039;key&#039;);\n\n\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u304b\u3089\u30c7\u30fc\u30bf\u53d6\u5f97\u6642\u306b\u3001\n\/\/ key\u304c\u5b58\u5728\u3057\u306a\u304b\u3063\u305f\u5834\u5408\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u8a2d\u5b9a\u3002\n$value = session(&#039;key&#039;, &#039;default&#039;);\n\n\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u306b\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3002\nsession(&#x5B;&#039;key&#039; =&gt; &#039;value&#039;]);\n<\/pre><\/div>\n\n\n<h2 id=\"toc7\" class=\"wp-block-heading\">\u30bb\u30c3\u30b7\u30e7\u30f3\u30d6\u30ed\u30c3\u30ad\u30f3\u30b0<\/h2>\n\n\n\n<p>\u7279\u5b9a\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u306e\u540c\u6642\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u5236\u9650\u3067\u304d\u308b\u3002<br>\u4f7f\u3046\u306b\u306f\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u30d6\u30ed\u30c3\u30ad\u30f3\u30b0\u306e\u5fc5\u8981\u6761\u4ef6\u3092\u78ba\u8a8d\u3057\u305f\u3046\u3048\u3067\u3001<br>block\u30e1\u30bd\u30c3\u30c9\u3092\u30eb\u30fc\u30c8\u5b9a\u7fa9\u306b\u30c1\u30a7\u30a4\u30f3\u3055\u305b\u308c\u3070\u826f\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306f config\/session.php \u306b\u4fdd\u5b58\u3055\u308c\u3066\u3044\u308b\u3002\u30bb\u30c3\u30b7\u30e7\u30f3\u306e\u4fdd\u5b58\u5148\u3092\u9078\u629e\u3067\u304d\u308b\u3002\u9078\u629e\u80a2\u306f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u53c2\u7167\u3059\u308b\u3068\u826f\u3044\u3002 \u30bb\u30c3\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u3092\u64cd\u4f5c\u3059\u308b\u4e3b\u306a\u65b9\u6cd5\u306f\u3001ses [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[96],"tags":[88,81],"class_list":["post-956","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-laravel","tag-php"],"_links":{"self":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/956","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=956"}],"version-history":[{"count":3,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/956\/revisions"}],"predecessor-version":[{"id":959,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/956\/revisions\/959"}],"wp:attachment":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}