{"id":1585,"date":"2020-03-15T15:52:01","date_gmt":"2020-03-15T06:52:01","guid":{"rendered":"https:\/\/qol-kk.com\/wp2\/?p=1585"},"modified":"2020-03-15T15:52:45","modified_gmt":"2020-03-15T06:52:45","slug":"post-1585","status":"publish","type":"post","link":"https:\/\/qol-kk.com\/wp2\/blog\/2020\/03\/15\/post-1585\/","title":{"rendered":"Laravel\uff1aEloquent\u30671\u5bfe\u591a\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u306e@foreach\u3067\u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u6307\u5b9a\u30ab\u30e9\u30e0\u3067\u4e26\u3073\u66ff\u3048\u3057\u305f\u3044"},"content":{"rendered":"<h2>Laravel\uff1aEloquent\u30671\u5bfe\u591a\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u306e@foreach\u3067\u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u6307\u5b9a\u30ab\u30e9\u30e0\u3067\u4e26\u3073\u66ff\u3048\u3057\u305f\u3044<\/h2>\n<p>\u3084\u308a\u65b9\u306b\u3064\u3044\u3066\u5c11\u3057\u60a9\u3093\u3060\u306e\u3067\u5099\u5fd8\u9332\u3067\u3059\u3002<\/p>\n<p>\u73fe\u5728\u3001\u4f5c\u6210\u3057\u305f\u30b7\u30b9\u30c6\u30e0\u306e\u30de\u30cb\u30e5\u30a2\u30eb\u3092\u4f5c\u6210\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001HTML\u3092\u66f8\u304f\u306e\u306f\u3068\u3066\u3082\u9762\u5012\u306a\u306e\u3067\u300cDB\u306b\u66f8\u3044\u3066\u547c\u3073\u51fa\u3057\u3066HTML\u5408\u6210\u3059\u308b\u300d\u305d\u3093\u306a\u5f62\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u4e2d\u3067\u3001JOIN\u5148\u306e\u5024\u3092\u4e26\u3073\u66ff\u3048\u3066\u53d6\u308a\u305f\u3044\u3068\u304d\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3093\u306a\u6642\u306e\u5bfe\u5fdc\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<h3>\u666e\u901a\u306b\u3084\u308b\u3068\u5b50\u30c6\u30fc\u30d6\u30eb\u5074\u306fID\u306e\u9806\u306b\u53d6\u308c\u308b<\/h3>\n<pre class=\"lang:default decode:true\">#table:manuals\r\nSchema::create('manuals', function (Blueprint $table) {\r\n    $table-&gt;increments('id');\r\n    $table-&gt;string('title')-&gt;comment('\u30bf\u30a4\u30c8\u30eb');\r\n    $table-&gt;unsignedInteger('selecter_id')-&gt;nullable()-&gt;comment('\u5206\u985e');\r\n    $table-&gt;integer('sortnumber')-&gt;comment('\u4e26\u3073\u9806');\r\n    $table-&gt;integer('manualsentence_id')-&gt;comment('\u30de\u30cb\u30e5\u30a2\u30eb\u69cb\u6210\u30d1\u30fc\u30c4ID');\r\n    $table-&gt;softDeletes();\r\n    $table-&gt;timestamps();\r\n    });\r\n\r\n#table:manualsources\r\nSchema::create('manualsources', function (Blueprint $table) {\r\n    $table-&gt;increments('id');\r\n    $table-&gt;string('subtitle')-&gt;comment('\u30b5\u30d6\u30bf\u30a4\u30c8\u30eb');\r\n    $table-&gt;unsignedInteger('manual_id')-&gt;nullable()-&gt;comment('\u89aaID');\r\n    $table-&gt;integer('sortnumber')-&gt;comment('\u4e26\u3073\u9806');\r\n    $table-&gt;softDeletes();\r\n    $table-&gt;timestamps();\r\n    });<\/pre>\n<p>\u3053\u308c\u3092View\u3067\u53d6\u308a\u51fa\u3059\u3068\u304d\u3001\u3053\u3093\u306a\u611f\u3058\u3067\u66f8\u304f\u3068\u53d6\u308a\u51fa\u3055\u308c\u308b $souce-&gt;subtitle \u306f manualsources-&gt;id\u306e\u9806\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">#manualController.edit\u3067Manual\u306e\u62bd\u51fa\r\n\r\n $item = Manual::find($id);<\/pre>\n<pre class=\"lang:default decode:true\">#view\u3067$item\u304b\u3089manualsource\u3092\u53d6\u308a\u51fa\u3059\r\n\r\n@foreach($item-&gt;manualsouce as $souce)\r\n  {{$souce-&gt;subtitle}}\r\n@endoforeach<\/pre>\n<h3>\u5b50\u30c6\u30fc\u30d6\u30eb\u306esortnumber\u3067\u4e26\u3073\u66ff\u3048\u3066\u53d6\u5f97\u3059\u308b\u3068\u304d\u306f\u3072\u3068\u624b\u9593\u5fc5\u8981<\/h3>\n<p>@foreach \u306e\u969b\u306borderby\u3092\u4ed8\u3051\u52a0\u3048\u3066get() \u3057\u305f\u3082\u306e\u3092 foreach \u3059\u308b\u3088\u3046\u306b\u6307\u793a\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">@if(!empty($item-&gt;manualsouce))\r\n  @foreach($item-&gt;manualsouce()-&gt;orderBy('sortnumber','asc')-&gt;get() as $souce)\r\n    {{souce-&gt;subtitle}}\r\n  @endforeach\r\n@endif<\/pre>\n<p>\u3053\u308c\u3067\u3001\u60f3\u5b9a\u3057\u305f\u52d5\u304d(\u5b50\u30c6\u30fc\u30d6\u30eb\u306esortnumber \u9806)\u306b\u53d6\u5f97\u304c\u53ef\u80fd\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3064\u3044\u3067\u306b\u3082\u3046\u4e00\u3064<\/p>\n<h3>@if(!empty ()) + @foreach() \u3092 @forelse \u306b\u7f6e\u304d\u63db\u3048\u308b<\/h3>\n<pre class=\"lang:default decode:true\">@forelse($item-&gt;manualsouce()-&gt;orderBy('sortnumber','asc')-&gt;get() as $souce)\r\n  &lt;h4&gt;{{$souce-&gt;subtitle}}&lt;\/h4&gt;\r\n@empty\r\n   \uff5e\uff5e\u4f5c\u6210\u4e2d\uff5e\uff5e\r\n@endforelse<\/pre>\n<p>\u6ce8\u610f\u70b9\u306f@empty\u306e\u6307\u5b9a\u304c\u5fc5\u9808\u3067\u3042\u308b\u4e8b\u3002\u5024\u304c\u7121\u304f\u3066\u3082@empty\u3092\u914d\u7f6e\u3057\u3066\u3044\u306a\u3044\u3068\u30a8\u30e9\u30fc\u304c\u51fa\u307e\u3059\u3002<\/p>\n<h3>\u307e\u3068\u3081<\/h3>\n<p>@forelse\u3001\u77e5\u3089\u306a\u304b\u3063\u305f\u3002<\/p>\n<p>\u3053\u3053\u307e\u3067if+foreach \u3067\u66f8\u3044\u3066\u304d\u305f\u306e\u3067\u300c\u7d50\u69cb\u60a0\u9577\u306a\u66f8\u304d\u65b9\u3057\u3066\u305f\u3093\u3060\u306a\u3041\uff5e\u300d\u3068\u898b\u76f4\u3057\u3066\u307f\u305f\u3044\u6c17\u5206\u306b\u3082\u306a\u308a\u307e\u3059\u304c\u3001\u307e\u305a\u306f\u516c\u958b\u307e\u3067\u6301\u3063\u3066\u304b\u306a\u3044\u3068\u3067\u3059\u3002<\/p>\n<p>\u898b\u76f4\u3057\u6642\u306e\u30c1\u30a7\u30c3\u30af\u30dd\u30a4\u30f3\u30c8\u3068\u3057\u3066\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u9762\u767d\u3055\u3067\u3082\u3042\u308a\u307e\u3059\u304c\u3001\u601d\u3063\u305f\u4e8b\u3092\u3084\u308b\u65b9\u6cd5\u304c\u5fc5\u305a\u898b\u3064\u304b\u308b\u3063\u3066\u306e\u304c\u3046\u308c\u3057\u3044\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u3055\u3041\u9811\u5f35\u308d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel\uff1aEloquent\u30671\u5bfe\u591a\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u306e@foreach\u3067\u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u6307\u5b9a\u30ab\u30e9\u30e0\u3067\u4e26\u3073\u66ff\u3048\u3057\u305f\u3044 \u3084\u308a\u65b9\u306b\u3064\u3044\u3066\u5c11\u3057\u60a9\u3093\u3060\u306e\u3067\u5099\u5fd8\u9332\u3067\u3059\u3002 \u73fe\u5728\u3001\u4f5c\u6210\u3057\u305f\u30b7\u30b9\u30c6\u30e0\u306e\u30de\u30cb\u30e5\u30a2\u30eb\u3092\u4f5c\u6210\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001HTML [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":944,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"vkexunit_cta_each_option":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[34],"tags":[528,530,422,153,99,98,369,53,529],"class_list":["post-1585","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-memorandum","tag-forelse","tag-530","tag-eloquent","tag-laravel","tag-mysql","tag-php","tag-view","tag-53","tag-529"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/qol-kk.com\/wp2\/wp-content\/uploads\/2018\/11\/laravel_logo.png","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/1585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/comments?post=1585"}],"version-history":[{"count":0,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/1585\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/media\/944"}],"wp:attachment":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/media?parent=1585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/categories?post=1585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/tags?post=1585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}