{"id":11504,"date":"2023-03-27T07:00:31","date_gmt":"2023-03-26T22:00:31","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=11504"},"modified":"2023-03-19T18:27:21","modified_gmt":"2023-03-19T09:27:21","slug":"laravel-%e3%81%ae-enum-%e3%82%92inertia-js%e3%81%a7%e3%82%b9%e3%83%9e%e3%83%bc%e3%83%88%e3%81%ab%e6%89%b1%e3%81%86%e6%96%b9%e6%b3%95-%e3%81%93%e3%82%8c%e3%81%a7%e7%85%a9%e3%82%8f%e3%81%97%e3%81%84","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=11504","title":{"rendered":"Laravel \u306e Enum \u3092Inertia.js\u3067\u30b9\u30de\u30fc\u30c8\u306b\u6271\u3046\u65b9\u6cd5 &#8211; \u3053\u308c\u3067\u7169\u308f\u3057\u3044\u5b9a\u6570\u5b9a\u7fa9\u306b\u30b5\u30e8\u30ca\u30e9\uff01"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u6700\u8fd1\u306f<code>Laravel + Inertia<\/code>\uff08<code>React<\/code>\uff06<code>Vue 3<\/code>\uff09\u306e\u958b\u767a\u304c\u591a\u304f\u306a\u3063\u3066\u304d\u305f\u306e\u3067\u3059\u304c\u3001\u3084\u306f\u308a<code>Inertia<\/code>\u3092\u4f7f\u3046\u3068<code>API<\/code>\u958b\u767a\u304c\u3059\u3063\u3068\u3070\u305b\u308b\u306e\u3067\u3001\u3068\u3066\u3082\u5feb\u9069\u306b\u958b\u767a\u3067\u304d\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3001\uff11\u70b9\u300c<strong>\u3046\u30fc\u3093\u2026<\/strong>\u300d\u3068\u601d\u3046\u3053\u3068\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u308c\u304c\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><strong style=\"font-size: 35px;\">\u300cEnum \u304c JavaScript \u5074\u3067\u53c2\u7167\u3067\u304d\u306a\u3044\ud83d\ude05\u300d<\/strong><\/p>\n<p>\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u305d\u308a\u3083\u3042\u3001<code>Enum<\/code>\u306f<code>PHP<\/code>\u3067\u30bb\u30c3\u30c8\u3057\u3066\u3044\u308b\u3082\u306e\u306a\u306e\u3067\u5f53\u7136\u306a\u3093\u3067\u3059\u304c\u3001\u6bce\u56de\u6bce\u56de\u30d3\u30e5\u30fc\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u30bb\u30c3\u30c8\u3059\u308b\u306e\u304c\u30e1\u30f3\u30c9\u30af\u30b5\u30a4\u3093\u3067\u3059\u3088\u306d\u2026<\/p>\n<p>\u3053\u3093\u306a\u30ab\u30f3\u30b8\u3067\u3059\u306d\u3002<br \/>\n\u2193\u2193\u2193<\/p>\n<div>\n<pre>Inertia::render('Test', <strong>['enum_values' =&gt; $enum_values]<\/strong>);<\/pre>\n<p>\u3061\u306a\u307f\u306b\u3001\u4ee5\u524d\u516c\u958b\u3057\u305f\u300c<a href=\"https:\/\/blog.capilano-fw.com\/?p=11314\">Laravel + Inertia + React \u3067\u591a\u8a00\u8a9e\u5316\u3059\u308b<\/a>\u300d\u3068\u540c\u3058\u3088\u3046\u306b\u30da\u30fc\u30b8\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3073\u306b\u81ea\u52d5\u3067<code>Inertia<\/code>\u3078\u30c7\u30fc\u30bf\u3092\u9001\u3063\u3066\u3082\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u3082\uff11\u70b9\u3060\u3051\u300c\u3046\u30fc\u3093\u2026\u300d\u306a\u3053\u3068\u304c\u3042\u3063\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u306f\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><strong style=\"font-size: 35px;\">\u300c\u52d5\u7684\u306b\u30c7\u30fc\u30bf\u53d6\u5f97\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u5165\u529b\u88dc\u5b8c\u304c\u52b9\u304b\u306a\u3044\ud83d\ude2b\u300d<\/strong><\/p>\n<p>\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\uff08\u79c1\u304c\u4f7f\u3063\u3066\u3044\u308b\uff09<code>phpstorm<\/code>\u3067\u30c7\u30fc\u30bf\u3092\u5165\u529b\u3059\u308b\u6642\u306b\u6bce\u56de\u300c<strong>\u3048\u30fc\u3063\u3068\u3001\u3042\u308c\u306e\u5024\u306f\u306a\u3093\u3060\u3063\u3051\u304b\uff1f\uff1f<\/strong>\u300d\u3068<code>Enum<\/code>\u30d5\u30a1\u30a4\u30eb\u3092\u898b\u306b\u3044\u304b\u306a\u3044\u3068\u3044\u3051\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u308f\u3051\u3067\u3059\u3002<\/p>\n<p>\uff08\u4f8b\u3048\u3070\u3001\u300c<strong>Food.<\/strong>\u300d\u3068\u5165\u529b\u3057\u305f\u6642\u70b9\u3067\u30ab\u30ec\u30fc\u3068\u304b\u30d4\u30b6\u3068\u304b\u306e\u5019\u88dc\u304c\u51fa\u3066\u307b\u3057\u3044\u3093\u3067\u3059\uff09<\/p>\n<\/div>\n<p>\u305d\u3053\u3067\u2757<\/p>\n<p>\u4e00\u8a08\u3092\u6848\u3058\u3066\u3001\u300c<code>Laravel<\/code>\u5074\u306e<code>Enum<\/code>\u304c\u81ea\u52d5\u7684\u306b<code>Inertia<\/code>\u5074\u306b\u6e21\u3055\u308c\u308b\u3088\u3046\u306b\u3059\u308b\u65b9\u6cd5\u300d\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u305f\u3002\u3057\u304b\u3082\u5165\u529b\u88dc\u5b8c\u306b\u3082\u5bfe\u5fdc\u3057\u3066\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u4f55\u304b\u306e\u53c2\u8003\u306b\u306a\u308a\u307e\u3057\u305f\u3089\u5b09\u3057\u3044\u3067\u3059\u3002\ud83d\ude04\u2728<\/p>\n<p>\u203b \u3061\u306a\u307f\u306b<code>PHP<\/code>\u306e<code>Enum<\/code>\u306f<code>8.1<\/code>\u304b\u3089\u4f7f\u3048\u308b\u6a5f\u80fd\u3067\u3059\u3002\u304a\u6c17\u3092\u3064\u3051\u304f\u3060\u3055\u3044\uff01<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9470 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13.png\" alt=\"\" width=\"294\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13.png 294w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13-276x300.png 276w\" sizes=\"auto, (max-width: 294px) 100vw, 294px\" \/>\u300c\u795e\u6238\u306e\u540d\u5e97\u30db\u30eb\u30e2\u30f3\u713c\u304d<br \/>\n\u3081\u3061\u3083\u304f\u3061\u3083\u30a6\u30de\u304b\u3063\u305f\u2757<br \/>\n\u30db\u30eb\u30e2\u30f3\uff11\u672c60\u5186\ud83d\udc4d\u300d<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> PHP 8.1\u3001Laravel 10.x\u3001Vite\u3001Inertia.js\u3001React 18<\/p>\n<h1>Enum\uff08\u5217\u6319\u578b\uff09\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u307e\u305a\u306f<code>Inertia<\/code>\u5074\u3078\u6e21\u3057\u305f\u3044<code>Enum<\/code>\u3092\u3064\u304f\u308a\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u308f\u304b\u308a\u3084\u3059\u304f\u300c<strong>\u98df\u3079\u7269<\/strong>\u300d\u306b\u95a2\u3059\u308b\u30c7\u30fc\u30bf\u3067\u3064\u304f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>app\/Enums\/Food.php<\/strong><\/p>\n<div>\n<pre><strong>&lt;?php<\/strong>\r\n\r\n<strong>namespace App\\Enums;<\/strong>\r\n\r\n<strong>enum Food: int<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    case Pizza = 1;     \/\/ \u30d4\u30b6<\/strong>\r\n<strong>    case Pasta = 2;     \/\/ \u30d1\u30b9\u30bf<\/strong>\r\n<strong>    case Burger = 3;    \/\/ \u30cf\u30f3\u30d0\u30fc\u30ac\u30fc<\/strong>\r\n<strong>    case Curry = 4;     \/\/ \u30ab\u30ec\u30fc<\/strong>\r\n<strong>    case Ramen = 5;     \/\/ \u30e9\u30fc\u30e1\u30f3<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p>\u3061\u306a\u307f\u306b<code>Enum<\/code>\u3068\u306f\u3001\u30b7\u30f3\u30d7\u30eb\u306b\u8a00\u3046\u3068\u300c<strong>\u5b9a\u6570\uff08\u5909\u66f4\u3055\u308c\u306a\u3044\u30c7\u30fc\u30bf\uff09<\/strong>\u300d\u3092\u30b0\u30eb\u30fc\u30d7\u3067\u7ba1\u7406\u3067\u304d\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<\/div>\n<h1>Enum \u306e\u30c7\u30fc\u30bf\u3092 JavaScript \u5316\u3059\u308b Artisan \u30b3\u30de\u30f3\u30c9\u3092\u3064\u304f\u308b<\/h1>\n<p>\u7d9a\u3044\u3066\u3001\u5148\u307b\u3069\u3064\u304f\u3063\u305f<code>Enum<\/code>\u3092<code>JavaScript<\/code>\u3067\u3082\u8aad\u307f\u8fbc\u3081\u308b\u3088\u3046\u306b\u3059\u308b<code>Artisan<\/code>\u30b3\u30de\u30f3\u30c9\u3092\u3064\u304f\u308a\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<div>\n<pre><strong>php artisan make:command EnumToInertiaCommand<\/strong><\/pre>\n<\/div>\n<p>\u3059\u308b\u3068\u3001<code>Artisan<\/code>\u30b3\u30de\u30f3\u30c9\u7528\u306e\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\/Console\/Commands\/EnumToInertiaCommand.php<\/strong><\/p>\n<div>\n<pre><strong>&lt;?php<\/strong>\r\n\r\n<strong>namespace App\\Console\\Commands;<\/strong>\r\n\r\n<strong>use App\\Enums\\Food;<\/strong>\r\n<strong>use Illuminate\\Console\\Command;<\/strong>\r\n\r\n<strong>class EnumToInertiaCommand extends Command<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    protected $signature = 'enum_to_inertia';<\/strong>\r\n<strong>    protected $description = 'A command to convert enums to JavaScript';<\/strong>\r\n\r\n<strong>    \/\/ \u3053\u3053\u306b\u5909\u63db\u3057\u305f\u3044 Enum \u3092\u8ffd\u52a0\u3059\u308b<\/strong>\r\n<strong>    private $converting_enums = [<\/strong>\r\n<strong>        Food::class,<\/strong>\r\n<strong>    ];<\/strong>\r\n\r\n<strong>    public function handle(): void<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $js_code = '';<\/strong>\r\n\r\n<strong>        foreach ($this-&gt;converting_enums as $converting_enum) {<\/strong>\r\n\r\n<strong>            $enum_name = last(<\/strong>\r\n<strong>                explode('\\\\', $converting_enum)<\/strong>\r\n<strong>            );<\/strong>\r\n<strong>            $cases = call_user_func($converting_enum .'::cases');<\/strong>\r\n<strong>            $js_code .= 'window.'. $enum_name .' = {' . \"\\n\";<\/strong>\r\n\r\n<strong>            foreach ($cases as $case) {<\/strong>\r\n\r\n<strong>                $case_name = $case-&gt;name;<\/strong>\r\n<strong>                $case_value = $case-&gt;value;<\/strong>\r\n<strong>                $js_value = (is_string($case_value)) \/\/ \u6587\u5b57\u5217\u306e\u5834\u5408\u306f\u30af\u30a9\u30fc\u30c8\u3067\u56f2\u3080<\/strong>\r\n<strong>                    ? \"'\". $case_value .\"'\"<\/strong>\r\n<strong>                    : $case_value;<\/strong>\r\n<strong>                $js_code .= '    \"'. $case_name .'\": '. $js_value .',' . \"\\n\";<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n\r\n<strong>            $js_code .= '};'. \"\\n\";<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        $path = resource_path('js\/Constants.js');<\/strong>\r\n<strong>        file_put_contents($path, $js_code);<\/strong>\r\n\r\n<strong>        $this-&gt;info('Done!');<\/strong>\r\n<strong>    }<\/strong>\r\n<strong>}<\/strong><\/pre>\n<\/div>\n<p>\u3053\u306e\u4e2d\u3067\u306f\u3001<code>$converting_enums<\/code>\u306b\u30bb\u30c3\u30c8\u3055\u308c\u305f\u5168\u3066\u306e<code>Enum<\/code>\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3001<code>JavaScript<\/code>\u306e\u30b3\u30fc\u30c9\u3092\u751f\u6210\u3002\u305d\u3057\u3066\u3001\u305d\u308c\u3092\u30d5\u30a1\u30a4\u30eb<code>Constants.js<\/code>\u3078\u4fdd\u5b58\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u203b \u306a\u304a\u3001\u4eca\u56de\u306f\u30c6\u30b9\u30c8\u306a\u306e\u3067<code>key-value<\/code>\u5f62\u5f0f\u306e\u307f\u3067\u3059\u304c\u3001<code>JavaScript<\/code>\u3067\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u9806\u756a\u304c\u4fdd\u6301\u3067\u304d\u306a\u3044\uff08\u78ba\u7d04\u3055\u308c\u3066\u3044\u306a\u3044\uff09\u306e\u3067\u3001\u5b9f\u969b\u306b\u306f\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\u3082\u5408\u308f\u305b\u3066\u751f\u6210\u3059\u308b\u3088\u3046\u306b\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<h1>\u30b3\u30de\u30f3\u30c9\u304c\u30d3\u30eb\u30c9\u6642\u306b\u81ea\u52d5\u5b9f\u884c\u3055\u308c\u308b\u3088\u3046\u306b\u3059\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5148\u307b\u3069\u306e<code>Artisan<\/code>\u30b3\u30de\u30f3\u30c9\u304c<code>Vite<\/code>\u306e\u30d3\u30eb\u30c9\u6642\u306b\u81ea\u52d5\u7684\u306b\u5b9f\u884c\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong>package.json<\/strong><\/p>\n<div>\n<pre>{\r\n    \"private\": true,\r\n    \"scripts\": {\r\n        \"dev\": \"vite\",\r\n        \"build\": \"<strong>php artisan enum_to_inertia &amp;&amp;<\/strong> vite build\"\r\n    },\r\n\r\n    \/\/ \u7701\u7565<\/pre>\n<\/div>\n<p>\u3053\u3053\u3067\u306f\u3001\u521d\u671f\u72b6\u614b\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u90e8\u5206\u306b<code>php artisan enum_to_inertia &amp;&amp; <\/code>\u3092\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<div>\n<pre>\"build\": \"vite build\"<\/pre>\n<p>\u3053\u3046\u3059\u308b\u3053\u3068\u3067\u3001\u30d3\u30eb\u30c9\u6642\u306b\u4ee5\u4e0b\uff12\u3064\u306e\u6d41\u308c\u3067\u5b9f\u884c\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li>Enum \u306e\u30c7\u30fc\u30bf\u3092 JavaScript \u5316<\/li>\n<li>\u901a\u5e38\u306e Vite \u306e\u30d3\u30eb\u30c9<\/li>\n<\/ol>\n<p>\u3061\u306a\u307f\u306b\u3001\u4eca\u56de\u306f\u30d3\u30eb\u30c9\u6642\u3060\u3051<code>JavaScript<\/code>\u5316\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u304c\u3001<code>dev<\/code>\u3067\u3082\u540c\u3058\u3088\u3046\u306b\u5b9f\u884c\u3057\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002\uff08\u6642\u9593\u304c\u304b\u304b\u308b\u53ef\u80fd\u6027\u3082\u3042\u308b\u306e\u3067\u4eca\u56de\u306f\u30d3\u30eb\u30c9\u6642\u306e\u307f\u306b\u3057\u307e\u3057\u305f\uff09<\/p>\n<div>\n<pre>\"dev\": \"<strong>php artisan enum_to_inertia &amp;&amp;<\/strong> vite\",<\/pre>\n<\/div>\n<\/div>\n<p>\u3053\u308c\u3067\u81ea\u52d5\u7684\u306b<code>Enum<\/code>\u3092<code>JavaScript<\/code>\u5316\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<h1>\u5b9a\u6570\u306e\u8aad\u307f\u8fbc\u307f<\/h1>\n<p>\u7d9a\u3044\u3066\u3001\u5148\u307b\u3069\u306e<code>JavaScript<\/code>\u5316\u3057\u305f\u5b9a\u6570\u30d5\u30a1\u30a4\u30eb\u306f\u305d\u306e\u307e\u307e\u3067\u306f<code>Vite<\/code>\u3067\u6709\u52b9\u306b\u306a\u3063\u3066\u3044\u306a\u3044\u306e\u3067\u3001<code>app.jsx<\/code>\u3078\u306e\u30bb\u30c3\u30c8\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<div>\n<pre>import '.\/bootstrap';\r\nimport '..\/css\/app.css';\r\n\r\nimport { createRoot } from 'react-dom\/client';\r\nimport { createInertiaApp } from '@inertiajs\/react';\r\nimport { resolvePageComponent } from 'laravel-vite-plugin\/inertia-helpers';\r\n<strong>import '.\/Constants'; \/\/ \ud83d\udc48 \u3053\u3053\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f<\/strong>\r\n\r\nconst appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';\r\n\r\n\/\/ \u7701\u7565<\/pre>\n<\/div>\n<p>\u3055\u3041\u3001\u3053\u308c\u3067\u4f5c\u696d\u306f\u5168\u3066\u5b8c\u4e86\u3067\u3059\u3002<br \/>\n\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\ud83d\ude04<\/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<p>\u307e\u305a\u306f<code>Enum<\/code>\u306e\u5b9a\u6570\u306e\u4e2d\u8eab\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306e\u30da\u30fc\u30b8\u3092\u30b5\u30b5\u30c3\u3068\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<p><strong>routes\/web.php<\/strong><\/p>\n<div>\n<pre><strong>use Inertia\\Inertia;<\/strong>\r\n\r\n\/\/ \u7701\u7565\r\n\r\n<strong>Route::get('constants', fn() =&gt; Inertia::render('Constants'));<\/strong><\/pre>\n<\/div>\n<p>\u305d\u3057\u3066\u3001\u30d3\u30e5\u30fc\u3067\u3059\u3002<\/p>\n<p><strong>resources\/js\/Pages\/Constants.jsx<\/strong><\/p>\n<div>\n<pre><strong>export default function Constants() {\r\n\r\n    const FoodKeys = Object.keys(Food);\r\n\r\n    return (\r\n        &lt;div className=\"p-5\"&gt;\r\n            {FoodKeys.map((key) =&gt; (\r\n                &lt;div key={key}&gt;{key}: {Food[key]}&lt;\/div&gt;\r\n            ))}\r\n        &lt;\/div&gt;\r\n    );\r\n\r\n}<\/strong><\/pre>\n<p>\u3055\u3041\u3001\u3053\u308c\u3067\u6e96\u5099\u306f\u6574\u3044\u307e\u3057\u305f\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067<code>Vite<\/code>\u306e\u30d3\u30eb\u30c9\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<div>\n<pre><strong>npm run build<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<\/div>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11507\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2023\/03\/laravel_enum_to_inertia_1.png\" alt=\"\" width=\"338\" height=\"292\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2023\/03\/laravel_enum_to_inertia_1.png 338w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2023\/03\/laravel_enum_to_inertia_1-300x259.png 300w\" sizes=\"auto, (max-width: 338px) 100vw, 338px\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\u300c<strong>Enum \u2192 JavaScript<\/strong>\u300d\u5316\u3057\u305f<code>Constants.js<\/code>\u304c\u4f5c\u6210\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p>\u307e\u305a\u306f\u6210\u529f\u3067\u3059\ud83d\ude04\ud83d\udc4d<\/p>\n<p>\u3061\u306a\u307f\u306b\u4e2d\u8eab\u306f\u3053\u3046\u306a\u3063\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<div>\n<pre><strong>window.Food = {<\/strong>\r\n<strong>    \"Pizza\": 1,<\/strong>\r\n<strong>    \"Pasta\": 2,<\/strong>\r\n<strong>    \"Burger\": 3,<\/strong>\r\n<strong>    \"Curry\": 4,<\/strong>\r\n<strong>    \"Ramen\": 5,<\/strong>\r\n<strong>};<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u3001\u30b0\u30ed\u30fc\u30d0\u30eb\u306a\u5909\u6570\u3068\u3057\u3066<code>Food<\/code>\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u306d\u3002<\/p>\n<p>\u3067\u306f\u3001\u5148\u307b\u3069\u3064\u304f\u3063\u305f\u30c6\u30b9\u30c8\u30da\u30fc\u30b8\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<p>\u3046\u307e\u304f\u3044\u304f\u3067\u3057\u3087\u3046\u304b\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11510\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2023\/03\/laravel_enum_to_inertia_3.png\" alt=\"\" width=\"128\" height=\"161\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\u3046\u307e\u304f<code>Enum<\/code>\u304b\u3089\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u3067\u306f\u3001\u4eca\u56de\u91cd\u8981\u306a\u70b9\u3068\u3057\u3066\u5192\u982d\u3067\u3082\u66f8\u3044\u305f\u300c<strong>\u5165\u529b\u88dc\u5b8c<\/strong>\u300d\u304c\u3046\u307e\u304f\u3044\u304f\u304b\u3092\u6700\u5f8c\u306b\u30c1\u30a7\u30c3\u30af\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u30c6\u30b9\u30c8\u30da\u30fc\u30b8\u306e\u9014\u4e2d\u306b\u300c<strong>Food.<\/strong>\u300d\u3068\u5165\u529b\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u3059\u308b\u3068\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11506\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2023\/03\/laravel_enum_to_inertia_2.png\" alt=\"\" width=\"699\" height=\"301\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2023\/03\/laravel_enum_to_inertia_2.png 699w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2023\/03\/laravel_enum_to_inertia_2-300x129.png 300w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n<code>Enum<\/code>\u306e\u5165\u529b\u88dc\u5b8c\u304c\u3046\u307e\u304f\u50cd\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u3059\u3079\u3066\u6210\u529f\u3067\u3059\ud83d\ude04\u2728<\/p>\n<h1>\u4f01\u696d\u69d8\u3078\u306e\u3054\u63d0\u6848<\/h1>\n<p>\u4eca\u56de\u306e\u3088\u3046\u306b\u3001<code>PHP<\/code>\u5074\u306e\u30c7\u30fc\u30bf\u3092<code>JavaScript<\/code>\u5316\u3059\u308b\u3053\u3068\u3067\u3001<code>PHP<\/code>\u306e\u30c7\u30fc\u30bf\u3092<code>JavaScript<\/code>\uff08\u4eca\u56de\u306f<code>React<\/code>\uff09\u5185\u3067\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001\u3055\u3089\u306b\u5165\u529b\u88dc\u5b8c\u3082\u52b9\u304f\u3088\u3046\u306b\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u958b\u767a\u52b9\u7387\u3082\u3042\u304c\u308b\u3053\u3068\u9593\u9055\u3044\u306a\u3057\u3067\u3059\u3002<\/p>\n<p>\u3082\u3057\u305d\u3046\u3044\u3063\u305f\u52b9\u7387\u7684\u306a\u958b\u767a\u3092\u884c\u3044\u305f\u3044\u5834\u5408\u306f\u305c\u3072\u304a\u554f\u3044\u5408\u308f\u305b\u304b\u3089\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u304a\u5f85\u3061\u3057\u3066\u304a\u308a\u307e\u3059\uff01<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Laravel<\/code>\u3067<code>Enum<\/code>\u3092<code>JavaScript<\/code>\u5316\u3057\u3001\u5b9a\u6570\u3068\u3057\u3066<code>React<\/code>\u5185\u304b\u3089\u53c2\u7167\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u4eca\u56de\u306f<code>React<\/code>\u3067\u3057\u305f\u304c\u3084\u308a\u65b9\u3068\u3057\u3066\u306f\u540c\u3058\u306a\u306e\u3067<code>Vue<\/code>\u3084<code>svelte<\/code>\u3067\u3082\u4f7f\u3048\u308b\u3093\u3058\u3083\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u307e\u305f\u3001\u4eca\u56de\u306e\u30a2\u30a4\u30c7\u30a2\u306f\u3046\u308d\u899a\u3048\u306a\u306e\u3067\u3059\u304c\u3001\u305f\u3057\u304b<code>laravel-ide-helper<\/code>\u304c\u540c\u3058\u3088\u3046\u306a\u4ed5\u7d44\u307f\u3067\u5b9f\u88c5\u3057\u3066\u308b\u3093\u3058\u3083\u306a\u304b\u3063\u305f\u3063\u3051\u2026\ud83e\udd14\u3068\u601d\u3063\u305f\u3053\u3068\u304c\u767a\u7aef\u3067\u3057\u305f\u3002\uff08\u3064\u307e\u308a\u3001\u3084\u308a\u65b9\u3068\u3057\u3066\u306f\u30d1\u30af\u30ea\u3067\u3059\u3002\u5929\u624d\u305f\u3061\u3001\u3044\u3064\u3082\u3042\u308a\u304c\u3068\u3046\uff01\uff09<\/p>\n<p>\u306a\u304a\u3001\u4eca\u56de\u306e\u4ef6\u3067\u4e00\u70b9\u3060\u3051\u6c17\u3092\u3064\u3051\u3066\u3044\u305f\u3060\u304d\u305f\u3044\u306e\u304c\u3001\u300c<strong>\u5916\u306b\u51fa\u3057\u3066\u306f\u3044\u3051\u306a\u3044\u30c7\u30fc\u30bf\u3092\u5b9a\u6570\u5316\u3057\u3066\u3057\u307e\u3046<\/strong>\u300d\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001<code>Laravel<\/code>\u306e\u30b3\u30f3\u30d5\u30a3\u30b0\u306b\u306f\u30ad\u30fc\u306a\u3069\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u306e\u3067\u5b89\u6613\u306b\u5b9a\u6570\u5316\u3059\u308b\u3053\u3068\u306f\u3057\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u4fbf\u5229\u3055\u306e\u88cf\u306b\u306f\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u4e0a\u306e\u61f8\u5ff5\u3082\u5b58\u5728\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u306d\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-4445 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2.png\" alt=\"\" width=\"370\" height=\"310\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2-300x251.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/>\u300c\u30b7\u30e3\u30a6\u30a8\u30c3\u30bb\u30f3\u306b<br \/>\n\u65e8\u307f\u3072\u308d\u304c\u308b\u9999\u308a\u767d\u3060\u3057\u3092\u304b\u3051\u308b<br \/>\n\u2026\u795e\u3067\u3059\u306a\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u6700\u8fd1\u306fLaravel + Inertia\uff08React\uff06Vue 3\uff09\u306e\u958b\u767a\u304c\u591a\u304f\u306a\u3063\u3066\u304d\u305f\u306e\u3067\u3059\u304c\u3001\u3084\u306f\u308aInertia\u3092\u4f7f\u3046\u3068API\u958b\u767a\u304c\u3059\u3063\u3068\u3070\u305b\u308b &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=11504\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Laravel \u306e Enum \u3092Inertia.js\u3067\u30b9\u30de\u30fc\u30c8\u306b\u6271\u3046\u65b9\u6cd5 &#8211; \u3053\u308c\u3067\u7169\u308f\u3057\u3044\u5b9a\u6570\u5b9a\u7fa9\u306b\u30b5\u30e8\u30ca\u30e9\uff01&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":11512,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[247,3,118,248],"tags":[250],"class_list":["post-11504","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-inertia-js","category-laravel","category-react-js","category-vite","tag-enum"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/11504","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=11504"}],"version-history":[{"count":5,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/11504\/revisions"}],"predecessor-version":[{"id":11515,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/11504\/revisions\/11515"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/11512"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}