{"id":2866,"date":"2021-06-20T07:03:15","date_gmt":"2021-06-19T22:03:15","guid":{"rendered":"https:\/\/www.wetch.co.jp\/?p=2866"},"modified":"2022-01-25T22:22:15","modified_gmt":"2022-01-25T13:22:15","slug":"laravel%e3%81%ae%e3%82%b3%e3%83%ac%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%ef%bc%88%e3%81%9d%e3%81%ae%ef%bc%91%ef%bc%90%ef%bc%9a%e6%9d%a1%e4%bb%b6%e5%88%86%e5%b2%90%ef%bc%8f%e3%82%b3%e3%83%ac%e3%82%af","status":"publish","type":"post","link":"https:\/\/www.wetch.co.jp\/note\/laravel%e3%81%ae%e3%82%b3%e3%83%ac%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%ef%bc%88%e3%81%9d%e3%81%ae%ef%bc%91%ef%bc%90%ef%bc%9a%e6%9d%a1%e4%bb%b6%e5%88%86%e5%b2%90%ef%bc%8f%e3%82%b3%e3%83%ac%e3%82%af\/","title":{"rendered":"Laravel\u306e\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08\u305d\u306e\uff11\uff10\uff1a\u6761\u4ef6\u5206\u5c90\uff0f\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u751f\u6210\uff09"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Laravel\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u6398\u308a\u4e0b\u3052\u30b7\u30ea\u30fc\u30ba\u7b2c\u5341\u5f3e\u3002\u4eca\u56de\u306f\u6761\u4ef6\u5206\u5c90\u30e1\u30bd\u30c3\u30c9\u3001\u304a\u3088\u3073\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u751f\u6210\u3092\u884c\u3046\u30e1\u30bd\u30c3\u30c9\u306b\u95a2\u3057\u3066\u78ba\u8a8d\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br>\u4f8b\u306b\u3088\u3063\u3066\u4e21\u8005\u306b\u7279\u306b\u5bc6\u63a5\u306a\u95a2\u4fc2\u304c\u3042\u308b\u8a33\u3067\u306f\u306a\u3044\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u3089\u5206\u985e\u306b\u5c5e\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u6570\u304c\u5c11\u306a\u3044\u305f\u3081\u3001\u307e\u3068\u3081\u3066\u6574\u7406\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">unless<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>$col = collect(&#91;1,2,3]);\n\n$condition = true;\n$col-&gt;unless($condition, function($collection) {\n    return $collection-&gt;push(4);\n});\n\n$condition = false;\n$col-&gt;unless($condition, function($collection) {\n    return $collection-&gt;push(5);\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e00\u5f15\u6570\u304c\u507d\u306e\u5834\u5408\u306e\u307f\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u5185\u5bb9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002\u5143\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u81ea\u4f53\u304c\u66f4\u65b0\u3055\u308c\u308b\u70b9\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<br>\u307e\u305f\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u5f15\u6570\u306f\u5f53\u8a72\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u81ea\u8eab\u3067\u3042\u308b\u70b9\u3082\u8981\u6ce8\u610f\u3067\u3059\u3002<br>\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>array:4 &#91;\n  0 =&gt; 1\n  1 =&gt; 2\n  2 =&gt; 3\n  3 =&gt; 5\n]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">when<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>$col = collect(&#91;1,2,3]);\n\n$condition = true;\n$col-&gt;when($condition, function($collection) {\n    return $collection-&gt;push(4);\n});\n\n$condition = false;\n$col-&gt;when($condition, function($collection) {\n    return $collection-&gt;push(5);\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">unless\u306e\u9006\u3067\u3001\u7b2c\u4e00\u5f15\u6570\u304c\u771f\u306e\u5834\u5408\u306e\u307f\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u5185\u5bb9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<br>\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>array:4 &#91;\n  0 =&gt; 1\n  1 =&gt; 2\n  2 =&gt; 3\n  3 =&gt; 4\n]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">whenEmpty(unlessNotEmpty)&nbsp;<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>$col = collect(&#91;1,2,3]);\n\n$col-&gt;whenEmpty(function($collection) {\n    return $collection-&gt;push(4);\n});\n\n$col = collect(&#91;]);\n\n$col-&gt;whenEmpty(function($collection) {\n    return $collection-&gt;push(5);\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5143\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u304c\u7a7a\u306e\u5834\u5408\u306e\u307f\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002\u4f8b\u306b\u3088\u3063\u3066\u3001\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u5f15\u6570\u306f\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u81ea\u8eab\u3067\u3001\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u5b9f\u884c\u7d50\u679c\u3082\u81ea\u8eab\u306b\u53cd\u6620\u3055\u308c\u307e\u3059\u3002<br>unlessNotEmpty\u306f\u30a8\u30a4\u30ea\u30a2\u30b9\u3067\u3059\u3002<br>\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\uff081\u3064\u76ee\u306e\u5b9f\u884c\u7d50\u679c\uff09\narray:3 &#91;\n  0 =&gt; 1\n  1 =&gt; 2\n  2 =&gt; 3\n]\n\uff082\u3064\u76ee\u306e\u5b9f\u884c\u7d50\u679c\uff09\narray:1 &#91;\n  0 =&gt; 5\n]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">whenNotEmpty(unlessEmpty) &nbsp;<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>$col = collect(&#91;1,2,3]);\n\n$col-&gt;whenNotEmpty(function($collection) {\n    return $collection-&gt;push(4);\n});\n\n$col = collect(&#91;]);\n\n$col-&gt;whenNotEmpty(function($collection) {\n    return $collection-&gt;push(5);\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">whenEmpty\u306e\u9006\u3067\u3001\u5143\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u304c\u7a7a\u3067\u306a\u3044\u5834\u5408\u306e\u307f\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<br>unlessEmpty\u306f\u30a8\u30a4\u30ea\u30a2\u30b9\u3067\u3059\u3002<br>\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\uff081\u3064\u76ee\u306e\u5b9f\u884c\u7d50\u679c\uff09\narray:4 &#91;\n  0 =&gt; 1\n  1 =&gt; 2\n  2 =&gt; 3\n  3 =&gt; 4\n]\n\uff082\u3064\u76ee\u306e\u5b9f\u884c\u7d50\u679c\uff09\n&#91;]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">collect<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4eca\u307e\u3067\u69d8\u3005\u306a\u30b5\u30f3\u30d7\u30eb\u3067\u4f7f\u3063\u3066\u304d\u307e\u3057\u305f\u306e\u3067\u4eca\u66f4\u3067\u3059\u304c\u3001\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u751f\u6210\u3057\u307e\u3059\u3002<br>\u4f7f\u3044\u65b9\u306f\u4f8b\u793a\u3059\u308b\u307e\u3067\u3082\u306a\u3044\u304b\u3068\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">make<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>$col = \\Illuminate\\Support\\Collection::make(&#91;1,2,3]);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u751f\u6210\u3057\u307e\u3059\u3002<br>\u30cd\u30c3\u30c8\u60c5\u5831\u306a\u3069\u3067\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306a\u7c21\u6613\u306a\u66f8\u5f0f\u3067\u3082\u6709\u52b9\u3067\u3042\u308b\u3088\u3046\u306b\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u5c11\u306a\u304f\u3068\u3082\u79c1\u304c\u8a66\u3057\u305f\u7bc4\u56f2\u3067\u306f\u30c0\u30e1\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$col = Collection::make(&#91;1,2,3]);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3044\u305a\u308c\u306b\u3057\u3066\u3082\u3001collect\u3092\u4f7f\u3063\u305f\u65b9\u304c\u7c21\u5358\u306a\u306e\u3067\u3001\u672c\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3053\u3068\u306f\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">times<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>$col = \\Illuminate\\Support\\Collection::times(3, function($num) {\n    return &#91;\n        'num' =&gt; $num,\n        'square' =&gt; $num * $num,\n    ];\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e00\u5f15\u6570\u306b\u6307\u5b9a\u3057\u305f\u6570\u3060\u3051\u3001\u7b2c\u4e8c\u5f15\u6570\u3067\u6307\u5b9a\u3057\u305f\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3092\u547c\u3073\u51fa\u3057\u3001\u305d\u306e\u7d50\u679c\u3067\u65b0\u3057\u3044\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u751f\u6210\u3057\u307e\u3059\u3002<br>\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u5f15\u6570\u306f\u4f55\u56de\u76ee\u306e\u547c\u3073\u51fa\u3057\u304b\uff08\uff11\u3001\uff12\u3001\uff13\u2026\uff09\u304c\u6e21\u3055\u308c\u307e\u3059\u3002<br>\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>array:3 &#91;\n  0 =&gt; array:2 &#91;\n    \"num\" =&gt; 1\n    \"square\" =&gt; 1\n  ]\n  1 =&gt; array:2 &#91;\n    \"num\" =&gt; 2\n    \"square\" =&gt; 4\n  ]\n  2 =&gt; array:2 &#91;\n    \"num\" =&gt; 3\n    \"square\" =&gt; 9\n  ]\n]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">unwrap<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>$result = \\Illuminate\\Support\\Collection::unwrap(collect(&#91;1,2,3]));\necho gettype($result).\"\\n\"; \/\/ array\n\n$result = \\Illuminate\\Support\\Collection::unwrap(&#91;1,2,3]);\necho gettype($result).\"\\n\"; \/\/ array\n\n$result = \\Illuminate\\Support\\Collection::unwrap(1);\necho gettype($result).\"\\n\"; \/\/ integer<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u304b\u3089\u672c\u4f53\u914d\u5217\u3092\u62bd\u51fa\u3059\u308b\u51e6\u7406\u3067\u3059\u3002<br>\u5f15\u6570\u3067\u6307\u5b9a\u3057\u305f\u30c7\u30fc\u30bf\u304c\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u4ee5\u5916\u3067\u3042\u308c\u3070\u305d\u306e\u30c7\u30fc\u30bf\u304c\u305d\u306e\u307e\u307e\u8fd4\u3055\u308c\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">wrap<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>$col1 = \\Illuminate\\Support\\Collection::wrap(collect(&#91;1,2,3]));\ndump($col1-&gt;toArray());\n\n$col2 = \\Illuminate\\Support\\Collection::wrap(&#91;1,2,3]);\ndump($col2-&gt;toArray());\n\n$col3 = \\Illuminate\\Support\\Collection::wrap(1);\ndump($col3-&gt;toArray());<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">unwrap\u306e\u9006\u3067\u3001\u5f15\u6570\u3067\u6307\u5b9a\u3057\u305f\u30c7\u30fc\u30bf\u3092\u6301\u3064\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u751f\u6210\u3057\u307e\u3059\u304c\u3001\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u304c\u6307\u5b9a\u3055\u308c\u305f\u5834\u5408\u306f\u305d\u306e\u307e\u307e\u8fd4\u3055\u308c\u307e\u3059\u3002<br>\u4e0a\u8a18\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\uff08$col1\uff09\narray:3 &#91;\n  0 =&gt; 1\n  1 =&gt; 2\n  2 =&gt; 3\n]\n\uff08$col2\uff09\narray:3 &#91;\n  0 =&gt; 1\n  1 =&gt; 2\n  2 =&gt; 3\n]\n\uff08$col3\uff09\narray:1 &#91;\n  0 =&gt; 1\n]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3057\u304b\u3057\u3001\u5f15\u6570\u306b\u6307\u5b9a\u3059\u308b\u5024\u306e\u578b\u304c\u4e0d\u5b9a\u3063\u3066\u3053\u3068\u306f\u3042\u307e\u308a\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3057\u3001\u666e\u901a\u306bcollect\u3092\u4f7f\u3048\u3070\u826f\u3044\u3088\u3046\u306b\u601d\u3044\u307e\u3059\u304c?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7dcf\u62ec<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u306e\u30ab\u30c6\u30b4\u30ea\u306b\u5c5e\u3059\u30e1\u30bd\u30c3\u30c9\u306b\u95a2\u3057\u3066\u306fcollect\u3092\u9664\u3044\u3066\u4f7f\u3063\u305f\u3053\u3068\u304c\u306a\u304f\u3001\u4eca\u5f8c\u3082\u3042\u307e\u308a\u4f7f\u3046\u3053\u3068\u304c\u306a\u3055\u305d\u3046\u306a\u5370\u8c61\u3067\u3059\u3002<br>\u3068\u8a00\u3046\u3053\u3068\u3067\u3001\u3042\u307e\u308a\u30b3\u30e1\u30f3\u30c8\u3059\u308b\u3053\u3068\u3082\u306a\u304f\u3001\u4eca\u56de\u306f\u7d42\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u6398\u308a\u4e0b\u3052\u30b7\u30ea\u30fc\u30ba\u7b2c\u5341\u5f3e\u3002\u4eca\u56de\u306f\u6761\u4ef6\u5206\u5c90\u30e1\u30bd\u30c3\u30c9\u3001\u304a\u3088\u3073\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u751f\u6210\u3092\u884c\u3046\u30e1\u30bd\u30c3\u30c9\u306b\u95a2\u3057\u3066\u78ba\u8a8d\u3057\u3066\u3044\u304d\u307e\u3059\u3002\u4f8b\u306b\u3088\u3063\u3066\u4e21\u8005\u306b\u7279\u306b\u5bc6\u63a5\u306a\u95a2\u4fc2\u304c\u3042\u308b\u8a33\u3067\u306f\u306a\u3044\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u3089\u5206\u985e\u306b\u5c5e\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u6570 [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":2867,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[210],"tags":[],"class_list":["post-2866","post","type-post","status-publish","format-standard","has-post-thumbnail","category-210"],"_links":{"self":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/posts\/2866","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/comments?post=2866"}],"version-history":[{"count":0,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/posts\/2866\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/media\/2867"}],"wp:attachment":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/media?parent=2866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/categories?post=2866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/tags?post=2866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}