{"id":658,"date":"2020-10-30T01:48:31","date_gmt":"2020-10-29T16:48:31","guid":{"rendered":"http:\/\/snow-cat.net\/?p=658"},"modified":"2022-11-12T14:53:06","modified_gmt":"2022-11-12T05:53:06","slug":"repository%e3%81%a7%e3%81%ae%e3%83%99%e3%82%b9%e3%83%88%e3%83%97%e3%83%a9%e3%82%af%e3%83%86%e3%82%a3%e3%82%b9","status":"publish","type":"post","link":"https:\/\/snow-cat.net\/?p=658","title":{"rendered":"\u50d5\u306e\u8003\u3048\u305f\u6700\u5f37\u306erepository\u30d1\u30bf\u30fc\u30f3(Laravel\u7de8)"},"content":{"rendered":"<p>\u7d76\u8cdb\u708e\u4e0a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u6bce\u65e5\u3072\u3043\u3072\u3043\u8a00\u3063\u3066\u308b\u3086\u304d\u306d\u3053\u3067\u3059\u3002<\/p>\n<p>\u73fe\u5728\u3001\u4f1a\u793e\u3067\u306fDB\u306e\u64cd\u4f5c\u3092\u30ea\u30dd\u30b8\u30c8\u30ea\u30d1\u30bf\u30fc\u30f3\u3067\u66f8\u3044\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u958b\u767a\u3059\u308b\u4e2d\u3067\u30df\u30b9\u3063\u305f\u306a\u3068\u611f\u3058\u305f\u308a\u6c5a\u3044\u306a\u3068\u611f\u3058\u308b\u3053\u3068\u304c\u3042\u3063\u305f\u306e\u3067\u3001\u3069\u3046\u3057\u305f\u3089\u7dba\u9e97\u306b\u958b\u767a\u3057\u3066\u3044\u3051\u308b\u304b\u8003\u3048\u305f\u306e\u3067\u66f8\u3044\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h2>\u554f\u984c\u70b9<\/h2>\n<p>\u305d\u3082\u305d\u3082\u3001\u4eca\u307e\u3067OR\u30de\u30c3\u30d1\u30fc\u3092\u4f7f\u3063\u305f\u958b\u767a\u3063\u3066\u3057\u305f\u3053\u3068\u306a\u304b\u3063\u305f\u3093\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u72ec\u81eaFW\u3067SQL\u306f\u751f\u3067\u66f8\u3044\u3066\u305f\u308a\u3001NoSQL\u3060\u3051\u3060\u3063\u305f\u308a&#8230;<\/p>\n<p>\u305d\u3093\u306a\u308f\u3051\u3067\u3001\u6700\u521d<strong>\u3069\u306e\u3050\u3089\u3044\u306e\u7c92\u5ea6\u3067\u95a2\u6570\u3092\u4f5c\u6210<\/strong>\u3057\u305f\u3089\u308f\u304b\u3093\u306a\u304b\u3063\u305f\u3093\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u306a\u308b\u3079\u304f\u5171\u901a\u5316\u3059\u308b\u3079\u304d\u304b\u3001\u305d\u308c\u3068\u3082\u7528\u9014\u3054\u3068\u306b\u95a2\u6570\u3092\u4f5c\u6210\u3057\u305f\u65b9\u304c\u3044\u3044\u306e\u304b\u3002<\/p>\n<h2>\u89e3\u6c7a\u7b56<\/h2>\n<p>\u60b6\u3005\u3068\u8003\u3048\u3066\u3044\u3066\u3001\u7d50\u69cb\u3053\u3046\u3057\u305f\u3089\u3044\u3044\u306a\u3063\u3066\u8003\u3048\u304c\u307e\u3068\u307e\u3063\u305f\u306e\u3067\u3001\u7d39\u4ecb\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001\u30d9\u30fc\u30b9\u306e\u30c8\u30ec\u30a4\u30c8\u306b\u5171\u901a\u3067\u4f7f\u7528\u3067\u304d\u308b\u95a2\u6570\u3092\u8a18\u8f09\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u5404\u30ea\u30dd\u30b8\u30c8\u30ea\u306f\u30c8\u30ec\u30a4\u30c8\u3092\u4f7f\u7528\u3057\u3066\u3001\u5404\u30ec\u30dd\u30b8\u30c8\u30ea\u72ec\u81ea\u306e\u95a2\u6570\u306f\u30ea\u30dd\u30b8\u30c8\u30ea\u306b\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u3053\u3046\u3059\u308b\u3053\u3068\u3067\u57fa\u672c\u7684\u306afind\u3084update\u306a\u3069\u306e\u95a2\u6570\u3092\u307e\u3068\u3081\u307e\u3059\u3002<\/p>\n<h3>base\u30c8\u30ec\u30a4\u30c8<\/h3>\n<p>\u5b9f\u969b\u306b\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n<pre class=\"theme:light-abite lang:php decode:true\" title=\"baseRipository\">trait baseRepositoryTrait\n{\n    public function find($id)\n    {\n        return $this-&gt;model-&gt;find($id);\n    }\n\n    public function findOrFail($id)\n    {\n        return $this-&gt;model-&gt;findOrFail($id);\n    }\n\n    public function first(array $params)\n    {\n        $model = $this-&gt;model;\n        foreach ($params as $key =&gt; $value) {\n            $model = $model-&gt;where($key, $value);\n        }\n        return $model-&gt;first();\n    }\n\n    public function firstOrFail(array $params)\n    {\n        $model = $this-&gt;model;\n        foreach ($params as $key =&gt; $value) {\n            $model = $model-&gt;where($key, $value);\n        }\n        return $model-&gt;firstOrFail();\n    }\n\n    public function search(array $params)\n    {\n        $model = $this-&gt;model;\n        foreach ($params as $key =&gt; $value) {\n            $model = $model-&gt;where($key, $value);\n        }\n        return $model-&gt;firstOrFail();\n    }\n}<\/pre>\n<p>\u30c7\u30fc\u30bf\u3092ID\u3067\u53d6\u5f97\u3059\u308b\u969b\u306b\u306ffind\u3068findOrFail\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u8a73\u7d30\u753b\u9762\u306a\u3069\u3067\u4f7f\u7528\u3059\u308b\u969b\u306b\u306ffindOrFail\u3001\u30ed\u30b8\u30c3\u30af\u306a\u3069\u3067\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306f\u306a\u304f\u3066\u3082\u3044\u3044\u5834\u5408\u306ffind\u306a\u3069\u3001\u305d\u308c\u305e\u308c\u306e\u7528\u9014\u304c\u3042\u308b\u306e\u3067\u305d\u306e\u307e\u307e\u63cf\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>first\u3068firstOrFail\u306f\u4e00\u5bfe\u591a\u306e\u30c7\u30fc\u30bf\u30e2\u30c7\u30eb\u3067\u6761\u4ef6\u3067\u7d5e\u308a\u8fbc\u3093\u30671\u4ef6\u3060\u3051\u53d6\u5f97\u3057\u305f\u3044\u969b\u306b\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u6761\u4ef6\u306b\u3088\u3063\u3066\u7d5e\u308a\u8fbc\u307f\u305f\u3044\u306e\u3067\u914d\u5217\u3067\u6e21\u3055\u308c\u305f\u5024\u3092foreach\u6587\u7d5e\u308a\u8fbc\u307f\u307e\u3059\u3002<\/p>\n<p>\u3053\u3093\u306a\u611f\u3058\u3067insert\u3084update\u3001delete\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h3>\u500b\u5225\u306e\u30ea\u30dd\u30b8\u30c8\u30ea<\/h3>\n<p>\u6b21\u306f\u500b\u5225\u306e\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u53d6\u308a\u3042\u3048\u3059\u30e6\u30fc\u30b6\u3067\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"theme:light-abite lang:php decode:true \" title=\"userRepository\">class userRepository\n{\n    use baseRipositoryTrait;\n\n    private $model;\n\n    private function __construct(User $model)\n    {\n        $this-&gt;model = $model;\n    }\n\n    public function findWithOrganization(int $id)\n    {\n        return $this-&gt;model-&gt;with('organization')-&gt;find($id);\n    }\n}<\/pre>\n<p>\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u306a\u3069\u306f\u5171\u901a\u5316\u51fa\u6765\u306a\u3044\u306e\u3067\u500b\u5225\u30ea\u30dd\u30b8\u30c8\u30ea\u306b\u63cf\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u3042\u3068\u3001\u95a2\u6570\u540d\u306f\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u3067\u66f8\u304f\u3088\u308a\u3082\u95a2\u6570\u306e\u8aac\u660e\u3067\u66f8\u304f\u65b9\u304c\u4f7f\u3044\u56de\u3057\u304c\u3067\u304d\u308b\u306e\u3067\u3001\u305d\u306e\u65b9\u304c\u3044\u3044\u3067\u3059\u304b\u306d\u3002<\/p>\n<p>\u30d9\u30fc\u30b9\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u7d99\u627f\u3059\u308b\u65b9\u6cd5\u3092\u8a18\u8f09\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u5b9f\u88c5\u3057\u3066\u307f\u305f\u3089\u52d5\u304b\u306a\u304b\u3063\u305f\u306e\u3067trait\u3092\u4f7f\u3046\u3088\u3046\u306b\u4fee\u6b63\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7d76\u8cdb\u708e\u4e0a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u6bce\u65e5\u3072\u3043\u3072\u3043\u8a00\u3063\u3066\u308b\u3086\u304d\u306d\u3053\u3067\u3059\u3002 \u73fe\u5728\u3001\u4f1a\u793e\u3067\u306fDB\u306e\u64cd\u4f5c\u3092\u30ea\u30dd\u30b8\u30c8\u30ea\u30d1\u30bf\u30fc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"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":[20],"tags":[],"class_list":["post-658","post","type-post","status-publish","format-standard","hentry","category-php"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pattVc-aC","jetpack-related-posts":[{"id":1019,"url":"https:\/\/snow-cat.net\/?p=1019","url_meta":{"origin":658,"position":0},"title":"\u6b63\u3057\u304f\u66f8\u3053\u3046PHP\u306e\u95a2\u6570","author":"hiro","date":"2021\u5e745\u670813\u65e5","format":false,"excerpt":"\u6b63\u3057\u304f\u3063\u3066\u4f55\u304c\u6b63\u3057\u3044\u306d\u3093\u3063\u3066\u601d\u3044\u307e\u3059\u304c\u3001\u3068\u308a\u3042\u3048\u305aPHP\u3067\u5b9f\u88c5\u3059\u308b\u969b\u306b\u6c17\u3092\u3064\u3051\u3066\u3044\u308b\u70b9\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002\u2026","rel":"","context":"PHP","block_context":{"text":"PHP","link":"https:\/\/snow-cat.net\/?cat=20"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1485,"url":"https:\/\/snow-cat.net\/?p=1485","url_meta":{"origin":658,"position":1},"title":"\u8cea\u554f\u3059\u308b\u969b\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8","author":"hiro","date":"2023\u5e745\u670828\u65e5","format":false,"excerpt":"\u524d\u306b\u6559\u80b2\u306b\u3064\u3044\u3066\u306e\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u304c\u3001\u305d\u3046\u3044\u3048\u3070\u8cea\u554f\u3092\u3059\u308b\u969b\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u3042\u3052\u3066\u3082\u5168\u304f\u4f7f\u308f\u308c\u306a\u304b\u3063\u305f\u306a\u2026","rel":"","context":"\u63a1\u7528\u30fb\u30ad\u30e3\u30ea\u30a2","block_context":{"text":"\u63a1\u7528\u30fb\u30ad\u30e3\u30ea\u30a2","link":"https:\/\/snow-cat.net\/?cat=2"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1327,"url":"https:\/\/snow-cat.net\/?p=1327","url_meta":{"origin":658,"position":2},"title":"\u81ea\u52d5\u30c6\u30b9\u30c8\u3092Laravel\u3067\u66f8\u304f\u3068\u304d\u306e\u30b3\u30c4","author":"hiro","date":"2022\u5e742\u67082\u65e5","format":false,"excerpt":"\u81ea\u52d5\u30c6\u30b9\u30c8\u3092\u65e9\u304f\u3067\u66f8\u3051\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u305f\u306e\u3067\u3001\u30b3\u30c4\u3067\u3082\u7d39\u4ecb\u3057\u3088\u3046\u304b\u3068\u601d\u3044\u307e\u3059\u3002 \u4eca\u56de\u306f\u30b3\u30de\u30f3\u30c9\u306e\u30c6\u30b9\u2026","rel":"","context":"\u305d\u306e\u4ed6\u3082\u308d\u3082\u308d","block_context":{"text":"\u305d\u306e\u4ed6\u3082\u308d\u3082\u308d","link":"https:\/\/snow-cat.net\/?cat=1"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":68,"url":"https:\/\/snow-cat.net\/?p=68","url_meta":{"origin":658,"position":3},"title":"jQuery\u3067\u4f5c\u308b\u7c21\u5358\u306a\u9023\u6253\u9632\u6b62\u51e6\u7406","author":"hiro","date":"2018\u5e7411\u670825\u65e5","format":false,"excerpt":"\u3053\u3093\u306b\u3061\u306f\u3001\u3086\u304d\u306d\u3053\u3067\u3059\u3002 \u4eca\u56de\u306fjQuery\u3067\u66f8\u304f\u9023\u6253\u9632\u6b62\u51e6\u7406\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002 \u30b3\u2026","rel":"","context":"JavaScript","block_context":{"text":"JavaScript","link":"https:\/\/snow-cat.net\/?cat=11"},"img":{"alt_text":"","src":"\/\/ir-jp.amazon-adsystem.com\/e\/ir?t=snowcat043-22&l=am2&o=9&a=B07Y3FJ885","width":350,"height":200},"classes":[]},{"id":133,"url":"https:\/\/snow-cat.net\/?p=133","url_meta":{"origin":658,"position":4},"title":"\u5e74\u672b\u306e\u30ea\u30ea\u30fc\u30b9","author":"hiro","date":"2019\u5e741\u67081\u65e5","format":false,"excerpt":"\u3053\u3093\u306b\u3061\u306f\u3001\u3086\u304d\u306d\u3053\u3067\u3059\u3002 \u5e2b\u5320\u304c\u8d70\u308b\u3068\u66f8\u3044\u3066\u5e2b\u8d70\u3068\u3044\u3046\u3088\u3046\u306b\u79c1\u306e\u5e74\u672b\u306f\u5207\u7fbd\u8a70\u307e\u3063\u305f\u30ea\u30ea\u30fc\u30b9\u3001\u305d\u3057\u3066\u2026","rel":"","context":"\u958b\u767a","block_context":{"text":"\u958b\u767a","link":"https:\/\/snow-cat.net\/?cat=9"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":171,"url":"https:\/\/snow-cat.net\/?p=171","url_meta":{"origin":658,"position":5},"title":"vue.js\u3067function\u3092\u4f7f\u308f\u306a\u3044\u3067\u66f8\u304f\u65b9\u6cd5(ES6\u5bfe\u5fdc)","author":"hiro","date":"2019\u5e744\u670829\u65e5","format":false,"excerpt":"\u3053\u3093\u306b\u3061\u308f\u3001\u3086\u304d\u306d\u3053\u3067\u3059\u3002 \u793e\u5185\u3067\u3082\u3063\u3068\u30e2\u30c0\u30f3\u306a\u958b\u767a\u30b9\u30bf\u30a4\u30eb\u3092\u53d6\u308a\u5165\u308c\u3088\u3046\u305c\u3063\u3066\u3053\u3068\u3067\u3001JavaSc\u2026","rel":"","context":"JavaScript","block_context":{"text":"JavaScript","link":"https:\/\/snow-cat.net\/?cat=11"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/snow-cat.net\/index.php?rest_route=\/wp\/v2\/posts\/658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/snow-cat.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/snow-cat.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/snow-cat.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/snow-cat.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=658"}],"version-history":[{"count":9,"href":"https:\/\/snow-cat.net\/index.php?rest_route=\/wp\/v2\/posts\/658\/revisions"}],"predecessor-version":[{"id":1520,"href":"https:\/\/snow-cat.net\/index.php?rest_route=\/wp\/v2\/posts\/658\/revisions\/1520"}],"wp:attachment":[{"href":"https:\/\/snow-cat.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/snow-cat.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/snow-cat.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}