{"id":9915,"date":"2019-03-15T20:57:57","date_gmt":"2019-03-15T11:57:57","guid":{"rendered":"https:\/\/www.itblog.jp\/?p=9915"},"modified":"2019-03-16T19:03:32","modified_gmt":"2019-03-16T10:03:32","slug":"laravel%e3%81%a7%e3%83%9e%e3%82%b9%e3%82%bf%e3%83%87%e3%83%bc%e3%82%bfkey-value%e3%83%87%e3%83%bc%e3%82%bf%e3%82%92%e3%81%a9%e3%81%86%e7%ae%a1%e7%90%86%e3%81%99%e3%82%8b%e3%81%8b","status":"publish","type":"post","link":"https:\/\/www.itblog.jp\/?p=9915","title":{"rendered":"Laravel\u3067\u30de\u30b9\u30bf\u30c7\u30fc\u30bf(key-value\u30c7\u30fc\u30bf)\u3092\u3069\u3046\u7ba1\u7406\u3059\u308b\u304b"},"content":{"rendered":"<p>Laravel\u3067\u3001\u30d5\u30a9\u30fc\u30e0\u3092\u4f5c\u308b\u6642\u306b\u3001\u4f8b\u3048\u3070\u9078\u629e\u30dc\u30c3\u30af\u30b9\u304c\u3042\u3063\u3066\u3001\u305d\u3053\u304b\u3089\u5024\u3092\u53d6\u308a\u51fa\u3057\u305f\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u6027\u5225[\u7537\u3001\u5973]\u3068\u304b\u3001\u90fd\u9053\u5e9c\u770c[\u5317\u6d77\u9053\u301c\u6c96\u7e04]\u3068\u304b\u3001\u30ab\u30c6\u30b4\u30ea[\u301c\u3001\u301c]\u3068\u304b\u8272\u3005\u3068\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u3089\u306e\u30c7\u30fc\u30bf\u306f\u3001\u3057\u3087\u3063\u3061\u3085\u3046\u5909\u66f4\u304c\u3042\u308b\u3082\u306e\u3067\u3001\u8907\u96d1\u306a\u3082\u306e\u3067\u3042\u308c\u3070\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u3063\u3066\u305d\u3053\u304b\u3089\u5f15\u3063\u5f35\u3063\u3066\u304f\u308b\u65b9\u6cd5\u3082\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u4f8b\u3048\u3070\u7537\u3001\u5973\u306e\u3088\u3046\u306a\u5c0f\u3055\u3044\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3067\u3042\u308c\u3070\u3001\u308f\u3056\u308f\u3056\u305d\u308c\u3092\u3059\u308b\u307b\u3069\u3067\u3082\u306a\u3044\u3068\u3044\u3046\u304b\u3001\u3044\u3061\u3044\u3061\u30c6\u30fc\u30d6\u30eb\u3092\u8ffd\u52a0\u3057\u3066\u30c7\u30fc\u30bf\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3068\u3044\u3046\u306e\u304c\u3001Laravel\u306e\u5834\u5408\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u3055\u306a\u3044\u3068\u3044\u3051\u306a\u304b\u3063\u305f\u308a\u3068\u8272\u3005\u3068\u9762\u5012\u3067\u3059\u3002<\/p>\n<p>\u305d\u306e\u5834\u5408\u306b\u4fbf\u5229\u306a\u3084\u308a\u65b9\u3067\u3059\u304c\u3001config\u306b\u8ffd\u52a0\u3059\u308b\u306e\u304c\u697d\u3067\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30da\u30fc\u30b8\u306b\u3084\u308a\u65b9\u304c\u66f8\u3044\u3066\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"https:\/\/qiita.com\/sakuraya\/items\/42fffe0f171d49ee74a0#_reference-634af529c0214d77de0b\">Laravel\u3067\u90fd\u9053\u5e9c\u770c\u306e\u30d7\u30eb\u30c0\u30a6\u30f3\u30e1\u30cb\u30e5\u30fc\u3092\u4f5c\u3063\u3066\u307f\u308b<\/a><\/p>\n<p>\u4e00\u5fdc\u624b\u9806\u306b\u3064\u3044\u3066\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059<\/p>\n<h2>\uff11\uff0econfig\u4ee5\u4e0b\u306b\u597d\u304d\u306a\u30d5\u30a1\u30a4\u30eb\u540d\u3067\u4f5c\u6210<\/h2>\n<p>\u90fd\u9053\u5e9c\u770c\u3067\u3042\u308c\u3070\u3001per.php\u306e\u3088\u3046\u306a\u30d5\u30a1\u30a4\u30eb\u540d\u3092config\u4ee5\u4e0b\u306b\u4f5c\u6210\u3057\u3066\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Null\">return array(\r\n  '1' =&gt; '\u5317\u6d77\u9053', \r\n  '2' =&gt; '\u9752\u68ee\u770c', \r\n\u7701\u7565\r\n  '46' =&gt; '\u9e7f\u5150\u5cf6\u770c', \r\n  '47' =&gt; '\u6c96\u7e04\u770c'\r\n);\r\n<\/pre>\n<p>\u3061\u306a\u307f\u306b\u3001config\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u6b8b\u3063\u3066\u3044\u308b\u3068\u53cd\u6620\u3055\u308c\u306a\u3044\u306e\u3067\u3001\u30d5\u30a1\u30a4\u30eb\u30a2\u30c3\u30d7\u5f8c\u306f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u304c\u5b9f\u884c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>php artisan config:cache<\/p>\n<p>\u4e0a\u8a18\u306e\u4f8b\u3067\u306f\u3001pref.php\u306b\u306f\u4e00\u3064\u3057\u304b\u914d\u5217\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u306a\u3044\u3067\u3059\u304c\u3001<br \/>\n\u8907\u6570\u5b9a\u7fa9\u3057\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u591a\u6b21\u5143\u914d\u5217\u3067\u3082\u8a2d\u5b9a\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Null\">return [\r\n    \"sex\" =&gt; [\r\n        \"1\" =&gt; \"\u7537\",\r\n        \"2\" =&gt; \"\u5973\",\r\n    ]\r\n];\r\n<\/pre>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3082\u3001\u5f8c\u3067\u554f\u984c\u306a\u304f\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3067\u53d6\u5f97\u2192\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u8868\u793a\u3001\u307e\u305f\u306f\u76f4\u63a5blade\u306b\u8868\u793a<\/h2>\n<p>\u4f5c\u6210\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u306f\u3001config(\u30d5\u30a1\u30a4\u30eb\u540d)\u3067\u3001\u3044\u3064\u3067\u3082\u53c2\u7167\u3057\u3066\u53d6\u5f97\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h3>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3067\u53d6\u5f97\u3057\u3066\u304b\u3089\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u8868\u793a\u3059\u308b\u65b9\u6cd5<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Null\">\r\npublic function sample() {\r\n  $prefs = config('pref');\r\n  return view('sample')-&gt;with(['prefs' =&gt; $prefs]);\r\n}<select>\r\n  @foreach($prefs as $index =&gt; $name)\r\n<option value=\"{{ $index }}\">$name<\/option>\r\n  @endforeach\r\n\r\n<\/select>\r\n\r\n<\/pre>\n<h2>\u76f4\u63a5\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u8a18\u8ff0\u3059\u308b<\/h2>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u76f4\u63a5\u53d6\u5f97\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;select name=\"_pref\"&gt;\r\n  @foreach(config('pref') as $index =&gt; $name)\r\n    &lt;option value=\"{{ $index }}\" @if(old('_pref') == $index) selected @endif&gt;$name&lt;\/option&gt;\r\n  @endforeach\r\n&lt;\/select&gt;<\/pre>\n<p>\u591a\u6b21\u5143\u914d\u5217\u306e\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u304b\u3093\u3058\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001config\/common.php\u306b<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Null\">return [\r\n    \"sex\" =&gt; [\r\n        \"1\" =&gt; \"\u7537\",\r\n        \"2\" =&gt; \"\u5973\",\r\n    ]\r\n];\r\n<\/pre>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306a\u5b9a\u7fa9\u3092\u4f8b\u3048\u3070common.php\u306b\u3057\u305f\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;select name=\"sex\"&gt;\r\n    @foreach(config('common.sex') as $index =&gt; $value)\r\n        &lt;option value='{{ $index }}' @if(old('sex') == $index) selected @endif &gt;{{ $value }}&lt;\/option&gt;\r\n    @endforeach\r\n&lt;\/select&gt;\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel\u3067\u3001\u30d5\u30a9\u30fc\u30e0\u3092\u4f5c\u308b\u6642\u306b\u3001\u4f8b\u3048\u3070\u9078\u629e\u30dc\u30c3\u30af\u30b9\u304c\u3042\u3063\u3066\u3001\u305d\u3053\u304b\u3089\u5024\u3092\u53d6\u308a\u51fa\u3057\u305f\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002 \u4f8b\u3048\u3070\u3001\u6027\u5225[\u7537\u3001\u5973]\u3068\u304b\u3001\u90fd\u9053\u5e9c\u770c[\u5317\u6d77\u9053\u301c\u6c96\u7e04]\u3068\u304b\u3001\u30ab\u30c6\u30b4\u30ea[\u301c\u3001\u301c]\u3068\u304b\u8272\u3005\u3068\u8003\u3048\u3089\u308c\u307e\u3059\u3002 \u305d\u308c\u3089\u306e\u30c7 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[140,131],"tags":[],"class_list":["post-9915","post","type-post","status-publish","format-standard","hentry","category-laravel","category-131"],"_links":{"self":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts\/9915","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9915"}],"version-history":[{"count":1,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts\/9915\/revisions"}],"predecessor-version":[{"id":9916,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts\/9915\/revisions\/9916"}],"wp:attachment":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}