{"id":8109,"date":"2020-10-12T12:00:31","date_gmt":"2020-10-12T03:00:31","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=8109"},"modified":"2020-10-05T17:02:44","modified_gmt":"2020-10-05T08:02:44","slug":"larave%e3%81%a7%e7%8b%ac%e8%87%aa%e3%83%90%e3%83%aa%e3%83%87%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92%e3%81%a4%e3%81%8f%e3%82%8b%ef%bc%88%e4%be%8b%ef%bc%9a%e3%83%8f%e3%83%b3%e3%83%90%e3%83%bc","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=8109","title":{"rendered":"Larave\u3067\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u304f\u308b\uff08\u4f8b\uff1a\u30cf\u30f3\u30d0\u30fc\u30ac\u30fc\u306e\u6ce8\u6587\uff09"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001<code>Laravel<\/code>\u306f\u5e38\u306b\u6539\u826f\u304c\u52a0\u3048\u3089\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u5c11\u3057\u8907\u96d1\u306a\u3053\u3068\u3092\u3059\u308b\u306b\u3057\u3066\u3082\u5de5\u592b\u3059\u308c\u3070\u307b\u307c\u4f55\u3067\u3082\u5bfe\u5fdc\u304c\u3067\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u305d\u3046\u306f\u3044\u3063\u3066\u3082\u4e16\u306e\u4e2d\u306e\u5168\u3066\u306b\u5bfe\u5fdc\u3067\u304d\u308b\u308f\u3051\u3067\u306f\u306a\u304f\u3001\u4e2d\u306b\u306f<strong>\u81ea\u5206\u3067\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u5834\u5408\u3082\u3042\u308a\u307e\u3059\u3002<\/strong><\/p>\n<p>\u305d\u3057\u3066\u3001\u4eca\u56de\u306f\u305d\u3093\u306a\u300c<strong>\u81ea\u5206\u3067\u5b9f\u88c5\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044<\/strong>\u300d\u304a\u8a71\u3068\u3057\u3066\u3001<\/p>\n<p><strong style=\"font-size: 35px;\">\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3<\/strong><\/p>\n<p>\u306e\u3064\u304f\u308a\u65b9\u3092\u3054\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u30fb\u30fb\u30fb\u3068\u3044\u3046\u306e\u3082\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u30eb\u30fc\u30eb\u306f\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3084URL\u306a\u3069\u3088\u304f\u4f7f\u3046\u3082\u306e\u306f\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u4f8b\u3048\u3070\u300c<strong>\u81ea\u793e\u3060\u3051\u306e\u30eb\u30fc\u30eb<\/strong>\u300d\u306a\u3069\u8907\u6570\u6761\u4ef6\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3084\u3063\u3068\u6b63\u3057\u3044\u5165\u529b\u304b\u3069\u3046\u304b\u304c\u308f\u304b\u308b\u3001\u3068\u3044\u3046\u5834\u5408\u3082\u3042\u308b\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u2757<\/p>\n<p>\u4eca\u56de\u306f<code>Laravel<\/code>\u3067\u72ec\u81ea\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30fb\u30eb\u30fc\u30eb\u3092\u3064\u304f\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u307e\u3057\u305f\u3089\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3566 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_1.png\" alt=\"\" width=\"306\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_1.png 306w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_1-287x300.png 287w\" sizes=\"auto, (max-width: 306px) 100vw, 306px\" \/>\u300c\u7d50\u5a5a\u5f0f\u306e\u304a\u8fd4\u3057\u306b\u3082\u3089\u3063\u305f<br \/>\n\u304a\u83d3\u5b50\u3001\u30a6\u30de\u30a6\u30de\u3067\u3057\u305f\ud83d\udc4d\u300d<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Laravel 8.x\uff08\u7d30\u304b\u306a\u3068\u3053\u308d\u306b\u9055\u3044\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u57fa\u672c\u7684\u306b\u4ee5\u524d\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u3082\u540c\u3058\u3067\u3059\uff09<\/p>\n<h1>\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>\u4eca\u56de\u3064\u304f\u308b\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306f\u3001\u79c1\u3082\u3088\u304f\u5229\u7528\u3055\u305b\u3066\u3082\u3089\u3063\u3066\u308b\u6709\u540d\u30cf\u30f3\u30d0\u30fc\u30ac\u30fc\u30fb\u30c1\u30a7\u30fc\u30f3\u306e\u6ce8\u6587\u3092\u4f8b\u306b\u3057\u305f\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u8a73\u3057\u3044\u30eb\u30fc\u30eb\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u30e2\u30fc\u30cb\u30f3\u30b0\u5546\u54c1\u306f\u300c5:00\u301c10:00\u300d\u3060\u3051\u6ce8\u6587OK<\/li>\n<li>\u30ec\u30ae\u30e5\u30e9\u30fc\u5546\u54c1\u306f\u300c5:00\u301c10:00\u300d\u306f\u6ce8\u6587\u3067\u304d\u306a\u3044\uff08\u305f\u3060\u3057\u30d5\u30a3\u30c3\u30b7\u30e5\u30d0\u30fc\u30ac\u30fc\u3060\u3051\u306f\u3044\u3064\u3067\u3082OK\uff09<\/li>\n<li>\u30c7\u30a3\u30fc\u30ca\u30fc\u5546\u54c1\u306f\u3001\u300c17:00\u301c5:00\u300d\u3060\u3051\u6ce8\u6587OK<\/li>\n<li>\u30c9\u30ea\u30f3\u30af\u306f\u3044\u3064\u3067\u3082\u6ce8\u6587OK<\/li>\n<\/ul>\n<p>\u203b\u5b8c\u5168\u306b\u30de\u25cf\u30c9\u30ca\u30eb\u30c9\u3092\u30a4\u30e1\u30fc\u30b8\u3057\u3066\u3044\u307e\u3059\u304c\u5546\u6a19\u6a29\u306a\u3069\u306e\u77e5\u8b58\u304c\u306a\u3044\u306e\u3067\u3001<strong>\u5ff5\u306e\u305f\u3081\u4f3c\u305f\u611f\u3058\u3067\u66f8\u304d\u307e\u3059<\/strong>\ud83d\ude02<\/p>\n<p>\u305d\u3057\u3066\u3001\u4f7f\u3046\u30c7\u30fc\u30bf\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<pre><strong>$foods = [<\/strong>\r\n<strong>    ['id' =&gt; 1, 'name' =&gt; '\u30a8\u30c3\u30b0\u30de\u30d5\u30a3\u30f3', 'type' =&gt; 'morning'],<\/strong>\r\n<strong>    ['id' =&gt; 2, 'name' =&gt; '\u30bd\u30fc\u30bb\u30fc\u30b8\u30de\u30d5\u30a3\u30f3', 'type' =&gt; 'morning'],<\/strong>\r\n<strong>    ['id' =&gt; 3, 'name' =&gt; '\u30cf\u30c3\u30b7\u30e5\u30dd\u30c6\u30c8', 'type' =&gt; 'morning'],<\/strong>\r\n<strong>    ['id' =&gt; 4, 'name' =&gt; '\u3066\u308a\u3084\u304d\u30d0\u30fc\u30ac\u30fc', 'type' =&gt; 'regular'],<\/strong>\r\n<strong>    ['id' =&gt; 5, 'name' =&gt; '\u30d5\u30a3\u30c3\u30b7\u30e5\u30d0\u30fc\u30ac\u30fc', 'type' =&gt; 'regular'],<\/strong>\r\n<strong>    ['id' =&gt; 6, 'name' =&gt; '\u30d5\u30e9\u30a4\u30c9\u30dd\u30c6\u30c8', 'type' =&gt; 'regular'],<\/strong>\r\n<strong>    ['id' =&gt; 7, 'name' =&gt; '\u7279\u5927\u30c1\u30fc\u30ba\u30d0\u30fc\u30ac\u30fc', 'type' =&gt; 'dinner'],<\/strong>\r\n<strong>    ['id' =&gt; 8, 'name' =&gt; '\u7279\u5927\u3066\u308a\u3084\u304d\u30d0\u30fc\u30ac\u30fc', 'type' =&gt; 'dinner'],<\/strong>\r\n<strong>    ['id' =&gt; 9, 'name' =&gt; '\u7279\u5927\u30d5\u30e9\u30a4\u30c9\u30dd\u30c6\u30c8', 'type' =&gt; 'dinner'],<\/strong>\r\n<strong>    ['id' =&gt; 10, 'name' =&gt; '\u30b3\u30fc\u30e9', 'type' =&gt; 'drink'],<\/strong>\r\n<strong>    ['id' =&gt; 11, 'name' =&gt; '\u30b7\u30a7\u30a4\u30af', 'type' =&gt; 'drink'],<\/strong>\r\n<strong>    ['id' =&gt; 12, 'name' =&gt; '\u7d05\u8336', 'type' =&gt; 'drink'],<\/strong>\r\n<strong>];<\/strong><\/pre>\n<p>\u3067\u306f\u5b9f\u969b\u306b\u958b\u767a\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u2757<\/p>\n<h1>\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30fb\u30eb\u30fc\u30eb\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u4eca\u56de\u5229\u7528\u3059\u308b\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30fb\u30eb\u30fc\u30eb<code>FoodOrder<\/code>\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:rule FoodOrder<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app\/Rules\/FoodOrder.php<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Rules;\r\n\r\nuse Illuminate\\Contracts\\Validation\\Rule;\r\n\r\nclass FoodOrder implements Rule\r\n{\r\n    <strong>private $error_message = ''; \/\/ \u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53ef\u5909\u306b\u3059\u308b\u305f\u3081\u306e\u30e1\u30f3\u30d0\u5909\u6570<\/strong>\r\n\r\n    <strong>public function passes($attribute, $value)<\/strong>\r\n    {\r\n        $result = false;\r\n        $foods = $this-&gt;getFoods(); \/\/ \u672c\u6765\u306fDB\u306a\u3069\u304b\u3089\u53d6\u5f97\u3057\u3066\u304f\u3060\u3055\u3044\r\n        $food_ids = $foods-&gt;pluck('id');\r\n        $food_id = intval($value);\r\n\r\n        if($food_ids-&gt;contains($food_id)) { \/\/ \u9078\u629e\u3057\u305f\u5546\u54c1\u306e\u5b58\u5728\u30c1\u30a7\u30c3\u30af\u3092\u3057\u3066\u3044\u307e\u3059\r\n\r\n            $food = $foods-&gt;where('id', $food_id)-&gt;first();\r\n            $food_type = $food['type']; \/\/ `morning`, `regular`, `dinner` or `drink`\r\n            $hour = now()-&gt;hour;\r\n\r\n            if($food_type === 'morning') { \/\/ \u30e2\u30fc\u30cb\u30f3\u30b0\u5546\u54c1\u306e\u5834\u5408\r\n\r\n                if($hour &gt;= 5 &amp;&amp; $hour &lt; 10) { \/\/ 5:00 \u301c 10:00 \u306a\u3089 true\r\n\r\n                    $result = true;\r\n\r\n                } else {\r\n\r\n                    $this-&gt;error_message = '\u30e2\u30fc\u30cb\u30f3\u30b0\u5546\u54c1\u304c\u6ce8\u6587\u3067\u304d\u308b\u306e\u306f\u300c5:00 \u301c 10:00\u300d\u3060\u3051\u3067\u3059\u3002';\r\n\r\n                }\r\n\r\n            } else if($food_type === 'regular') { \/\/ \u30ec\u30ae\u30e5\u30e9\u30fc\u5546\u54c1\u306e\u5834\u5408\r\n\r\n                if($food_id === 5) { \/\/ \u30d5\u30a3\u30c3\u30b7\u30e5\u30d0\u30fc\u30ac\u30fc\u306f\u3044\u3064\u3067\u3082\u6ce8\u6587OK\r\n\r\n                    $result = true;\r\n\r\n                } else if($hour &lt; 5 || $hour &gt;= 10) { \/\/ 5:00 \u301c 10:00 \u300c\u4ee5\u5916\u300d\u306a\u3089 true\r\n\r\n                    $result = true;\r\n\r\n                } else {\r\n\r\n                    $this-&gt;error_message = '\u30ec\u30ae\u30e5\u30e9\u30fc\u5546\u54c1\u306f\u300c5:00 \u301c 10:00\u300d\u306e\u6642\u9593\u5e2f\u306b\u306f\u6ce8\u6587\u3067\u304d\u307e\u305b\u3093\u3002';\r\n\r\n                }\r\n\r\n            } else if($food_type === 'dinner') { \/\/ \u30c7\u30a3\u30ca\u30fc\u5546\u54c1\u306e\u5834\u5408\r\n\r\n                if($hour &lt; 5 || $hour &gt;= 17) { \/\/ 17:00 \u301c 5:00 \u306a\u3089 true\r\n\r\n                    $result = true;\r\n\r\n                } else {\r\n\r\n                    $this-&gt;error_message = '\u30c7\u30a3\u30ca\u30fc\u5546\u54c1\u304c\u6ce8\u6587\u3067\u304d\u308b\u306e\u306f\u300c17:00 \u301c 5:00\u300d\u3060\u3051\u3067\u3059\u3002';\r\n\r\n                }\r\n\r\n            } else if($food_type === 'drink') { \/\/ \u30c9\u30ea\u30f3\u30af\u5546\u54c1\u306e\u5834\u5408\r\n\r\n                $result = true; \/\/ \u3044\u3064\u3082\u3067\u6ce8\u6587OK\r\n\r\n            }\r\n\r\n        } else {\r\n\r\n            $this-&gt;error_message = '\u3053\u306e\u5546\u54c1\u306f\u5b58\u5728\u3057\u3066\u3044\u307e\u305b\u3093\u3002';\r\n\r\n        }\r\n\r\n        <strong>return $result; \/\/ \u2461 true \u306a\u3089\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u901a\u904e\u3001false \u306a\u3089\u30a8\u30e9\u30fc<\/strong>\r\n    }\r\n\r\n    <strong>public function message()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        return $this-&gt;error_message; \/\/ \u2460 \u597d\u304d\u306a\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u30bb\u30c3\u30c8\u3067\u304d\u308b<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n    private function getFoods() {\r\n\r\n        return collect([\r\n            ['id' =&gt; 1, 'name' =&gt; '\u30a8\u30c3\u30b0\u30de\u30d5\u30a3\u30f3', 'type' =&gt; 'morning'],\r\n            ['id' =&gt; 2, 'name' =&gt; '\u30bd\u30fc\u30bb\u30fc\u30b8\u30de\u30d5\u30a3\u30f3', 'type' =&gt; 'morning'],\r\n            ['id' =&gt; 3, 'name' =&gt; '\u30cf\u30c3\u30b7\u30e5\u30dd\u30c6\u30c8', 'type' =&gt; 'morning'],\r\n            ['id' =&gt; 4, 'name' =&gt; '\u3066\u308a\u3084\u304d\u30d0\u30fc\u30ac\u30fc', 'type' =&gt; 'regular'],\r\n            ['id' =&gt; 5, 'name' =&gt; '\u30d5\u30a3\u30c3\u30b7\u30e5\u30d0\u30fc\u30ac\u30fc', 'type' =&gt; 'regular'],\r\n            ['id' =&gt; 6, 'name' =&gt; '\u30d5\u30e9\u30a4\u30c9\u30dd\u30c6\u30c8', 'type' =&gt; 'regular'],\r\n            ['id' =&gt; 7, 'name' =&gt; '\u7279\u5927\u30c1\u30fc\u30ba\u30d0\u30fc\u30ac\u30fc', 'type' =&gt; 'dinner'],\r\n            ['id' =&gt; 8, 'name' =&gt; '\u7279\u5927\u3066\u308a\u3084\u304d\u30d0\u30fc\u30ac\u30fc', 'type' =&gt; 'dinner'],\r\n            ['id' =&gt; 9, 'name' =&gt; '\u7279\u5927\u30d5\u30e9\u30a4\u30c9\u30dd\u30c6\u30c8', 'type' =&gt; 'dinner'],\r\n            ['id' =&gt; 10, 'name' =&gt; '\u30b3\u30fc\u30e9', 'type' =&gt; 'drink'],\r\n            ['id' =&gt; 11, 'name' =&gt; '\u30b7\u30a7\u30a4\u30af', 'type' =&gt; 'drink'],\r\n            ['id' =&gt; 12, 'name' =&gt; '\u7d05\u8336', 'type' =&gt; 'drink'],\r\n        ]);\r\n\r\n    }\r\n}<\/pre>\n<p>\u3067\u306f\u3001\u30b3\u30fc\u30c9\u306e\u5185\u5bb9\u3092\u3072\u3068\u3064\u305a\u3064\u3054\u7d39\u4ecb\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u2460 message()<\/h2>\n<p>\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u304b\u3089<strong>\u8fd4\u3055\u308c\u305f\u6587\u5b57\u5217\u304c\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u306a\u308a\u307e\u3059\u3002<\/strong><\/p>\n<p>\u305d\u3057\u3066\u3001\u4eca\u56de\u306f\u6761\u4ef6\u306b\u3088\u3063\u3066\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u5909\u308f\u308b\u306e\u3067\u3001<code>$error_message<\/code>\u3068\u3044\u3046\u3001<strong>\u3069\u306e\u30e1\u30bd\u30c3\u30c9\u304b\u3089\u3067\u3082\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u30e1\u30f3\u30d0\u5909\u6570<\/strong>\u3092\u7528\u610f\u3057\u3001\u305d\u306e\u4e2d\u8eab\u3092<code>return<\/code>\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u306a\u305c<code>public<\/code>\u3067\u306f\u306a\u304f<code>private<\/code>\u306b\u3057\u3066\u3044\u308b\u304b\u3068\u3044\u3046\u3068\u3001\u3053\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u306f\u30af\u30e9\u30b9\u306e\u5916\u304b\u3089\u306f\u30a2\u30af\u30bb\u30b9\u3059\u308b\u5fc5\u8981\u304c\u306a\u3044\uff08\u3068\u5224\u65ad\u3057\u305f\uff09\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u30a2\u30af\u30bb\u30b9\u3092\u906e\u65ad\u3057\u3066\u304a\u3051\u3070\u3001\u3082\u3057\u9593\u9055\u3063\u305f\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u305f\u3066\u3082\u30a8\u30e9\u30fc\u304c\u8868\u793a\u3055\u308c\u308b\u306e\u3067\u3001\u958b\u767a\u306e\u6b63\u78ba\u6027\u304c\u5411\u4e0a\u3057\u307e\u3059\u3088\ud83d\udc4d<\/p>\n<h2>\u2461 passes()<\/h2>\n<p>\u3082\u3057\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306b<code>true<\/code>\u3092\u8fd4\u305b\u3070\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u305f\u3053\u3068\u306b\u306a\u308a\u3001\u9006\u306b<code>false<\/code>\u306a\u3089\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306b\u3072\u3063\u304b\u304b\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u5f15\u6570\u3068\u3057\u3066\u53d6\u5f97\u3067\u304d\u308b<code>$value<\/code>\u306f\u9001\u4fe1\u30c7\u30fc\u30bf\u306e\u5024\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u3082\u3057<code>food_id<\/code>\u3068\u3044\u3046\u540d\u524d\u306e\u30c7\u30fc\u30bf\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u3057\u305f\u3044\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u4f7f\u3044\u65b9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>$request-&gt;validate([\r\n    <strong>'food_id'<\/strong> =&gt; [\r\n        'required',\r\n        <strong>new FoodOrder()<\/strong> \/\/ \ud83d\udc48 \u3053\u3053\u3067\u3059\r\n    ]\r\n]);<\/pre>\n<h2>__construct()\u3092\u4f7f\u3046\u5834\u5408<\/h2>\n<p>\u4eca\u56de<code>__construct()<\/code>\u306f\u7701\u7565\u3057\u307e\u3057\u305f\u304c\u3001\u4f8b\u3048\u3070\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3059\u308b\u3068\u304d\u306b\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u304c\u5fc5\u8981\u306a\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u3066<code>$user<\/code>\u3092\u9001\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Rules;\r\n\r\nuse App\\Models\\User;\r\nuse Illuminate\\Contracts\\Validation\\Rule;\r\n\r\nclass FoodOrder implements Rule\r\n{\r\n    private $error_message = ''; \/\/ \u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53ef\u5909\u306b\u3059\u308b\u305f\u3081\u306e\u30e1\u30f3\u30d0\u5909\u6570\r\n    <strong>private $user;<\/strong>\r\n\r\n<strong>    public function __construct(User $user)<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $this-&gt;user = $user; \/\/ \u3053\u3053\u3067\u30e1\u30f3\u30d0\u5909\u6570\u3078\u683c\u7d0d<\/strong>\r\n<strong>    }<\/strong><\/pre>\n<p>\u30e1\u30f3\u30d0\u5909\u6570\u306b\u683c\u7d0d\u3059\u308b\u3053\u3068\u3067\u3001<strong>\u3044\u3064\u3067\u3082\u3069\u306e\u30e1\u30bd\u30c3\u30c9\u304b\u3089\u3067\u3082\u683c\u7d0d\u3057\u305f\u60c5\u5831\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/strong><\/p>\n<pre>\/\/ \u7701\u7565<strong>\r\n\r\npublic function passes($attribute, $value)<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    if($this-&gt;user-&gt;type === 'premium') { \/\/ \ud83d\udc48 \u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b<\/strong>\r\n\r\n<strong>        return true; \/\/ \u30d7\u30ec\u30df\u30a2\u30e0\u4f1a\u54e1\u306f\u6642\u9593\u306b\u95a2\u4fc2\u306a\u304f\u4f55\u3067\u3082\u6ce8\u6587\u3067\u304d\u308b<\/strong>\r\n\r\n<strong>    }\r\n\r\n<\/strong>\/\/ \u7701\u7565<\/pre>\n<p>\u305d\u3057\u3066\u3001\u4f7f\u3044\u65b9\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<pre><strong>$user = User::find(1);<\/strong>\r\n\r\n$request-&gt;validate([\r\n    'food_id' =&gt; [\r\n        'required',\r\n        <strong>new FoodOrder($user)<\/strong> \/\/ \ud83d\udc48 \u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3082\u9001\u308b\r\n    ]\r\n]);<\/pre>\n<h1>\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u88c5\u3057\u3066\u3044\u304f<\/h1>\n<p>\u3067\u306f\u3001\u3053\u3053\u307e\u3067\u3067\u4f5c\u3063\u305f\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u88c5\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30eb\u30fc\u30c8\u3092\u3064\u304f\u308b<\/h2>\n<p><strong>routes\/web.php<\/strong><\/p>\n<pre><strong>Route::get('custom_validation_create', [HomeController::class, 'custom_validation_create']);<\/strong>\r\n<strong>Route::post('custom_validation_post', [HomeController::class, 'custom_validation_post']);<\/strong><\/pre>\n<p>\u203b \u306a\u304a\u3001<code>Laravel 8.x<\/code>\u3067\u306f\u30eb\u30fc\u30c8\u306e\u6307\u5b9a\u65b9\u6cd5\u304c\u82e5\u5e72\u5909\u66f4\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u8a73\u3057\u304f\u306f\u4ee5\u4e0b\u306eURL\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\ud83d\udcdd\u00a0<a href=\"https:\/\/blog.capilano-fw.com\/?p=7799#i-6\">Laravel 8.x \u306e\u65b0\u6a5f\u80fd\u30fb\u5909\u66f4\u70b9\u306e\u307e\u3068\u3081<\/a><\/p>\n<h2>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u3064\u304f\u308b<\/h2>\n<p>\u6b21\u306b\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3067\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:controller HomeController<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app\/Http\/Controllers\/HomeController.php<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Http\\Controllers;\r\n\r\nuse App\\Models\\Post;\r\nuse App\\Models\\User;\r\nuse App\\Rules\\FoodOrder;\r\nuse Carbon\\Carbon;\r\nuse Illuminate\\Http\\Request;\r\nuse Illuminate\\Http\\File;\r\nuse Illuminate\\Support\\Facades\\Storage;\r\n\r\nclass HomeController extends Controller\r\n{\r\n    <strong>public function custom_validation_create() {<\/strong>\r\n\r\n<strong>        return view('custom_validation_create');<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n<strong>    public function custom_validation_post(Request $request) {<\/strong>\r\n\r\n        <strong>\/\/ \ud83d\udc47 \u30c6\u30b9\u30c8\u7528\u306b\u300c\u73fe\u5728\u6642\u9593\u300d\u3092\u5909\u66f4\u3059\u308b<\/strong>\r\n<strong>        $test_hour = 16;<\/strong>\r\n<strong>        $dt = today()-&gt;setHour($test_hour);<\/strong>\r\n<strong>        Carbon::setTestNow($dt);<\/strong>\r\n\r\n<strong>        $request-&gt;validate([<\/strong>\r\n<strong>            'food_id' =&gt; [<\/strong>\r\n<strong>                'required',<\/strong>\r\n<strong>                new FoodOrder()<\/strong>\r\n<strong>            ]<\/strong>\r\n<strong>        ]);<\/strong>\r\n\r\n<strong>        return [<\/strong>\r\n<strong>            'result' =&gt; '\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u901a\u904e\uff01'<\/strong>\r\n<strong>        ];<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u306a\u304a\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u65b9\u6cd5\u306f\u5148\u307b\u3069\u7d39\u4ecb\u3057\u305f\u3068\u304a\u308a\u3067\u3059\u304c\u3001\u305d\u306e\u4ed6\u306b\u91cd\u8981\u306a\u306e\u304c\u3001\u300c<strong>\u30c6\u30b9\u30c8\u7528\u306b\u73fe\u5728\u6642\u9593\u3092\u5909\u66f4<\/strong>\u300d\u3057\u3066\u3044\u308b\u90e8\u5206\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u306f\u3001\u6642\u9593\u7ba1\u7406\u30d1\u30c3\u30b1\u30fc\u30b8<code>Carbon<\/code>\u306e\u30c6\u30b9\u30c8\u5411\u3051\u6a5f\u80fd\u3067\u3001\u4f8b\u3048\u3070\u4eca\u56de\u306e\u4f8b\u3067\u306f\u300c\u4eca\u304c16\u6642<strong>\u3068\u3057\u3066<\/strong>\u30b7\u30b9\u30c6\u30e0\u3092\u5b9f\u884c\u300d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30d3\u30e5\u30fc\u3092\u3064\u304f\u308b<\/h2>\n<p>\u6700\u5f8c\u306b\u30d3\u30e5\u30fc\u3067\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><strong>resources\/views\/custom_validation_create.blade.php<\/strong><\/p>\n<pre>&lt;html&gt;\r\n&lt;body&gt;\r\n&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/axios\/0.19.2\/axios.min.js\"&gt;&lt;\/script&gt;\r\n&lt;script&gt;\r\n\r\n    <strong>window.onload = () =&gt; {<\/strong>\r\n\r\n<strong>        const food_id = 3;<\/strong>\r\n<strong>        const url = '\/custom_validation_post';<\/strong>\r\n<strong>        const params = {<\/strong>\r\n<strong>            food_id: food_id,<\/strong>\r\n<strong>            _token: '{{ csrf_token() }}'<\/strong>\r\n<strong>        };<\/strong>\r\n<strong>        axios.post(url, params)<\/strong>\r\n<strong>            .then(response =&gt; { \/\/ \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306b\u6210\u529f\u3057\u305f\u3068\u304d<\/strong>\r\n\r\n<strong>                console.log(response);<\/strong>\r\n\r\n<strong>            })<\/strong>\r\n<strong>            .catch(error =&gt; { \/\/ \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306b\u5931\u6557\u3057\u305f\u3068\u304d<\/strong>\r\n\r\n<strong>                console.log(error);<\/strong>\r\n\r\n<strong>            });<\/strong>\r\n\r\n<strong>    };<\/strong>\r\n\r\n&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3053\u306e\u4e2d\u3067\u3084\u3063\u3066\u3044\u308b\u306e\u306f\u3001\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u305f\u3089\u3059\u3050\u306b<code>axios<\/code>\u3092\u4f7f\u3063\u3066\u306e<code>Ajax<\/code>\u9001\u4fe1\u3067\u3059\u3002\u4e2d\u8eab\u306f\u76ee\u5f53\u3066\u306e<code>food_id<\/code>\u3068\u3001<code>Laravel<\/code>\u306e<code>CSRF\u30c8\u30fc\u30af\u30f3<\/code>\uff08\u4e0d\u6b63\u30a2\u30af\u30bb\u30b9\u9632\u6b62\u7528\u306e\u6587\u5b57\u5217\uff09\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h1>\u3061\u306a\u307f\u306b\uff1a \u30c7\u30fc\u30bf\u304c\u7a7a\u3067\u3082\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\u306b\u306f<\/h1>\n<p>\u3072\u3068\u3064\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3067\u6c17\u3092\u3064\u3051\u3066\u304a\u304f\u3079\u304d\u3053\u3068\u306f\u300c<strong>\u9001\u4fe1\u30c7\u30fc\u30bf\u304c\u5b58\u5728\u3057\u306a\u3051\u308c\u3070\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306f\u5b9f\u884c\u3057\u306a\u3044<\/strong>\u300d\u3001\u3064\u307e\u308a\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u3066\u3057\u307e\u3046\u3068\u3044\u3046\u90e8\u5206\u3067\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>required<\/code>\u3092\u3064\u3051\u3066\u3044\u306a\u3051\u308c\u3070\u3001<code>food_id<\/code>\u304c\u7a7a\u3001\u3082\u3057\u304f\u306f\u5b58\u5728\u3057\u3066\u3044\u306a\u3044\u5834\u5408\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306f\u901a\u904e\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<pre>$request-&gt;validate([\r\n    'food_id' =&gt; [\r\n        <strong>new FoodOrder() \/\/ \ud83d\udc48 \u30c7\u30fc\u30bf\u304c\u306a\u3051\u308c\u3070\u901a\u904e\u3057\u3066\u3057\u307e\u3046\ud83d\ude2b<\/strong>\r\n    ]\r\n]);<\/pre>\n<p>\u307e\u305f\u3001\u4eca\u56de\u306e\u30b1\u30fc\u30b9\u306f<code>food_id<\/code>\u3068\u3044\u3046\u3072\u3068\u3064\u3060\u3051\u306e\u30c7\u30fc\u30bf\u3078\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3060\u3063\u305f\u306e\u3067\u554f\u984c\u306a\u304b\u3063\u305f\u3067\u3059\u304c\u3001\u4f8b\u3048\u3070\u8907\u6570\u306e\u30c7\u30fc\u30bf\u3092\u7dcf\u5408\u7684\u306b\u898b\u3066\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u5224\u65ad\u3059\u308b\u5834\u5408\u3001\u300c<strong>\u30c7\u30fc\u30bf\u304c\u3042\u308d\u3046\u304c\u306a\u304b\u308d\u3046\u304c\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306f\u5fc5\u305a\u5b9f\u884c\u3059\u308b<\/strong>\u300d\u5fc5\u8981\u304c\u51fa\u3066\u304f\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3093\u306a\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>ImplicitRule<\/code>\u3092\u4f7f\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Rules;\r\n\r\n<strong>use Illuminate\\Contracts\\Validation\\ImplicitRule;<\/strong> \/\/ <strong>\ud83d\udc48 \u8ffd\u52a0\u3057\u307e\u3057\u305f<\/strong>\r\n\r\nclass FoodOrder implements <strong>ImplicitRule \/\/ \ud83d\udc48 \u5909\u66f4\u3057\u307e\u3057\u305f<\/strong>\r\n{\r\n\r\n\/\/\u3000\u7701\u7565<\/pre>\n<p>\u3053\u3046\u3059\u308b\u3068\u3001\u5fc5\u305a\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u5b9f\u884c\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308b\u306e\u3067\u3001\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\uff08\u5b9f\u969b\u306b\u306f<code>food_order<\/code>\u3068\u3044\u3046\u30c7\u30fc\u30bf\u306f\u9001\u4fe1\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\uff09<\/p>\n<pre>$request-&gt;validate([\r\n    '<strong>food_order<\/strong>' =&gt; [\r\n        <strong>new FoodOrder()<\/strong> \/\/ \ud83d\udc48 \u3053\u3053\u306f\u5fc5\u305a\u5b9f\u884c\u3055\u308c\u307e\u3059\r\n    ]\r\n]);<\/pre>\n<p>\u3082\u3061\u308d\u3093<code>food_order<\/code>\u306e\u6587\u5b57\u5217\u306f\u3069\u3093\u306a\u3082\u306e\u3067\u3082OK\u3067\u3059\u3002<\/p>\n<p><span style=\"font-size: 1rem;\">\u305d\u3057\u3066\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u3068\u304d\u3001\u3053\u308c\u3068\u540c\u3058\u540d\u524d\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u53ef\u8aad\u6027\u3082\u3088\u304f\u306a\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8121\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/10\/laravel_custom_validation_rule_4.png\" alt=\"\" width=\"459\" height=\"98\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/10\/laravel_custom_validation_rule_4.png 459w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/10\/laravel_custom_validation_rule_4-300x64.png 300w\" sizes=\"auto, (max-width: 459px) 100vw, 459px\" \/><\/p>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<h2>\u308f\u3056\u3068\u9593\u9055\u3048\u3066\u307f\u308b<\/h2>\n<p>\u307e\u305a\u306f\u3001\u308f\u3056\u3068\u9593\u9055\u3048\u3066\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u304d\u3061\u3093\u3068\u62d2\u5426\u3059\u308b\u304b\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306e\u30b3\u30fc\u30c9\u3067\u306f\u300116\u6642\u3068\u3057\u3066\u52d5\u3044\u3066\u3044\u308b\u306e\u3067\u3053\u306e\u6642\u9593\u5e2f\u306b\u306f\u6ce8\u6587\u3067\u304d\u306a\u3044\u300c<strong>\u30e2\u30fc\u30cb\u30f3\u30b0\u5546\u54c1<\/strong>\u300d\u306eID\u3092\u9001\u4fe1\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>const food_id = 3; <\/strong>\/\/ \ud83d\udc48 \u30cf\u30c3\u30b7\u30e5\u30dd\u30c6\u30c8<\/pre>\n<p>\u9001\u4fe1\u5f8c\u3001<code>Google Chrome<\/code>\u306e\u958b\u767a\u30c4\u30fc\u30eb\u3067\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3068\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8110\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/10\/laravel_custom_validation_rule_1.png\" alt=\"\" width=\"720\" height=\"124\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/10\/laravel_custom_validation_rule_1.png 720w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/10\/laravel_custom_validation_rule_1-300x52.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/p>\n<p>\u306f\u3044\u275716\u6642\u306b\u30e2\u30fc\u30cb\u30f3\u30b0\u5546\u54c1\u306f\u6ce8\u6587\u3067\u304d\u306a\u3044\u306e\u3067\u3001\u6b63\u3057\u304f\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<h2>\u6ce8\u6587\u3067\u304d\u308b\u6ce8\u6587\u3067\u9001\u4fe1\u3059\u308b<\/h2>\n<p>\u3067\u306f\u3001\u6b21\u306b16\u6642\u306b\u6ce8\u6587\u3067\u304d\u308b\u300c\u30ec\u30ae\u30e5\u30e9\u30fc\u5546\u54c1\u300d\u306eID\u3092\u9001\u4fe1\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>const food_id = 4;<\/strong> \/\/ \ud83d\udc48 \u3066\u308a\u3084\u304d\u30d0\u30fc\u30ac\u30fc<\/pre>\n<p>\u9001\u4fe1\u3059\u308b\u3068\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8111\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/10\/laravel_custom_validation_rule_3.png\" alt=\"\" width=\"457\" height=\"126\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/10\/laravel_custom_validation_rule_3.png 457w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/10\/laravel_custom_validation_rule_3-300x83.png 300w\" sizes=\"auto, (max-width: 457px) 100vw, 457px\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\u4eca\u5ea6\u306f\u6ce8\u6587\u3067\u304d\u308b\u6642\u9593\u306a\u306e\u3067\u3001\u4e88\u60f3\u901a\u308a\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306f\u901a\u904e\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u6210\u529f\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<h1>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b<\/h1>\n<p>\u4eca\u56de\u5b9f\u969b\u306b\u958b\u767a\u3057\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u4e00\u5f0f\u3092\u4ee5\u4e0b\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\u3002<\/p>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/blog.capilano-fw.com?download=8115&amp;tmstv=1777532640\" rel=\"nofollow\" id=\"download-link-8115\" data-redirect=\"false\" >\n\tLarave\u3067\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u304f\u308b<\/a>\n\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u4eca\u56de\u306f\u3001\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u4f7f\u3044\u65b9\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3055\u3059\u304c\u306b\u4eca\u56de\u306e\u30b5\u30f3\u30d7\u30eb\u306e\u3088\u3046\u306b\u8907\u96d1\u306a\u72ec\u81ea\u30eb\u30fc\u30eb\u3092\u3064\u304f\u308b\u3053\u3068\u306f\u3081\u3063\u305f\u306b\u306a\u3044\u3068\u306f\u601d\u3044\u307e\u3059\u304c\u3001\u4e00\u5ea6\u3064\u304f\u3063\u3066\u304a\u304f\u3068\u3001<strong>\u4ed6\u306e\u5165\u529b\u3067\u540c\u3058\u30c1\u30a7\u30c3\u30af\u304c\u5fc5\u8981\u306b\u306a\u3063\u3066\u3082\u3001\u7c21\u5358\u306b\u4f7f\u3044\u56de\u3057\u304c\u3067\u304d\u3066\u4fbf\u5229<\/strong>\u3067\u3059\u3088\ud83d\udc4d<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306f\u3042\u308b\u7a2e\u300c\u8cc7\u7523\u300d\u3068\u3044\u3063\u3066\u3082\u3044\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u306d\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u3082\u6d3b\u7528\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\u2757<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6067 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_19.png\" alt=\"\" width=\"314\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_19.png 314w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_19-294x300.png 294w\" sizes=\"auto, (max-width: 314px) 100vw, 314px\" \/>\u300c\u660e\u65e5\u30a2\u30ec\u98df\u3079\u308b\u305e\u2757<br \/>\n\u2026\u3063\u3066\u601d\u3063\u3066\u3082\u3001\u8d77\u304d\u305f\u3089\u6b32\u3057\u304f\u306a\u3044\u306e\u306f\u3001<br \/>\n\u4e00\u4f53\u306a\u3093\u306a\u3093\u3067\u3057\u3087\u3046\u304b\uff08\u7b11\uff09\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001Laravel\u306f\u5e38\u306b\u6539\u826f\u304c\u52a0\u3048\u3089\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u5c11\u3057\u8907\u96d1\u306a\u3053\u3068\u3092\u3059\u308b\u306b\u3057\u3066\u3082\u5de5\u592b\u3059\u308c\u3070\u307b\u307c\u4f55\u3067\u3082\u5bfe\u5fdc\u304c\u3067\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u3002 \u3057\u304b\u3057\u3001\u305d\u3046\u306f\u3044\u3063\u3066\u3082\u4e16\u306e\u4e2d\u306e &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=8109\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Larave\u3067\u72ec\u81ea\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u304f\u308b\uff08\u4f8b\uff1a\u30cf\u30f3\u30d0\u30fc\u30ac\u30fc\u306e\u6ce8\u6587\uff09&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":8119,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,97],"tags":[5],"class_list":["post-8109","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","category-97","tag-5"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/8109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8109"}],"version-history":[{"count":10,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/8109\/revisions"}],"predecessor-version":[{"id":8126,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/8109\/revisions\/8126"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/8119"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}