{"id":1220,"date":"2019-05-31T09:34:48","date_gmt":"2019-05-31T00:34:48","guid":{"rendered":"https:\/\/qol-kk.com\/wp2\/?p=1220"},"modified":"2019-05-31T09:34:48","modified_gmt":"2019-05-31T00:34:48","slug":"post-1220","status":"publish","type":"post","link":"https:\/\/qol-kk.com\/wp2\/blog\/2019\/05\/31\/post-1220\/","title":{"rendered":"Laravel\uff1aCSV\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3067MySQL\u3092\u66f4\u65b0\u3059\u308b"},"content":{"rendered":"<h2>Laravel\uff1aCSV\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3067MySQL\u3092\u66f4\u65b0\u3059\u308b<\/h2>\n<p>2\u9031\u9593\u3076\u308a\u306e\u66f4\u65b0\u3068\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u3053\u306e\u9593\u8272\u3005\u3068\u60a9\u307fTry\uff06Error\u3092\u7e70\u8fd4\u3057\u3066\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u306e\u4e2d\u3067\u4ee5\u5916\u306b\u3082\u8d85\u7c21\u5358\u306b\u5b9f\u88c5\u51fa\u6765\u305fCSV\u306b\u3088\u308b\u30c7\u30fc\u30bf\u66f4\u65b0\u306b\u3064\u3044\u3066\u307e\u3068\u3081\u307e\u3059\u3002<\/p>\n<h3>\u7c21\u5358\u3060\u3063\u305fController\u3067\u306e\u5b9f\u88c5<\/h3>\n<p>PHP\u306e\u30d9\u30bf\u6253\u3061\u306e\u6642\u3068\u7570\u306a\u308a\u3001Laravel\u3067\u306fCSV\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9(\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9)\u306e\u8a18\u4e8b\u304cWEB\u4e0a\u306b\u6ca2\u5c71\u3042\u308a\u5b9f\u88c5\u306f\u975e\u5e38\u306b\u5bb9\u6613\u306b\u51fa\u6765\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u306e\u4e2d\u3067\u3082\u5d4c\u3063\u305f\u306e\u306f\u6b21\u306e\u4e8b\u3092\u8003\u3048\u305f\u6642\u3067\u3059\u3002<\/p>\n<div class=\"borderBox\">Model\u306b\u30d0\u30ea\u30c7\u30fc\u30bf\u3042\u308b\u3093\u3060\u304b\u3089\u3053\u3044\u3064\u547c\u3073\u51fa\u3057\u3066Validation\u3059\u308c\u3070\u3044\u3093\u3058\u3083\u306d\uff1f<\/div>\n<p>\u305d\u3093\u306a\u8003\u3048\u3066Controller\u304b\u3089Model\u306e\u30d0\u30ea\u30c7\u30fc\u30bf\u3092\u547c\u3073\u51fa\u3059\u306e\u3067\u3059\u304c\u30a8\u30e9\u30fc\u3002<\/p>\n<div class=\"borderBox\">\n<p>Type error: Argument 1 passed to App\\Http\\Controllers\\Controller::validate() must be an instance of Illuminate\\Http\\Request, instance of Illuminate\\Database\\Eloquent\\Collection given, called in hogehoge on line 122<\/p>\n<\/div>\n<p><strong>\u300c\u4f55\u6545\u4f7f\u3048\u306a\u3044\uff01\u300d<\/strong><\/p>\n<p>\u6700\u7d42\u7684\u306b\u3053\u306e\u7591\u554f\u3082\u89e3\u6c7a\u3059\u308b\u306b\u81f3\u308a\u307e\u3057\u305f\u304c\u3001\u30d0\u30ea\u30c7\u30fc\u30bf\u307e\u3067Controller\u306b\u8a18\u8f09\u3059\u308b\u4e8b\u306b...\u3002<\/p>\n<p>\u8907\u6570\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u66f4\u65b0\u3055\u305b\u305f\u3044\u79c1\u3068\u3057\u3066\u306f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306e\u80a5\u5927\u5316\u304c\u3068\u3066\u3082\u6c17\u306b\u306a\u308a\u307e\u3057\u305f\u304cCSV\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u66f4\u65b0\u306f\u975e\u5e38\u306b\u9806\u8abf\u306b\u52d5\u4f5c\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u6700\u3082\u53c2\u8003\u306b\u3055\u305b\u3066\u9802\u3044\u305f\u306e\u306f<a href=\"https:\/\/access-jp.co.jp\/blogs\/development\/389\">\u30a2\u30af\u30bb\u30b9\u30b8\u30e3\u30d1\u30f3\u3055\u3093\u306e\u8a18\u4e8b<\/a>\u3067\u3059\u3002<br \/>\n\u6709\u308a\u96e3\u3046\u5fa1\u5ea7\u3044\u307e\u3057\u305f\u3002<\/p>\n<h3>\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3092\u6587\u5b57\u3067\u66f8\u3044\u3066\u307f\u308b<\/h3>\n<p>\u5f8c\u306e\u81ea\u5206\u306e\u70ba\u306b\u3001\u3056\u3063\u304f\u308a\u3068\u52d5\u4f5c\u3092\u6587\u5b57\u304a\u8d8a\u3057\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<div class=\"borderBox\">\n<p>\u25a0 CSV\u30a4\u30f3\u30dd\u30fc\u30c8\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u00a0\u30101\u4ef6\u305a\u3064\u51e6\u7406version\u3011<\/p>\n<ol>\n<li>\u914d\u5217\u306e\u5217\u6570\u3092\u53d6\u5f97\u3059\u308b<\/li>\n<li>CSV\u30d5\u30a1\u30a4\u30eb\u306e1\u5217\u76ee\u3092\u30d8\u30c3\u30c0\u30fc\u3068\u3057\u3066\u53d6\u5f97\u3001\u5909\u6570\uff1a$column_\u5217\u9806 \u306b\u30d8\u30c3\u30c0\u30fc\u540d\u3092\u683c\u7d0d<br \/>\n\u203b \u3053\u306e\u51e6\u7406\u3067\u30ab\u30e9\u30e0\u306e\u9806\u756a\u304c\u5165\u308c\u66ff\u308f\u3063\u3066\u3044\u3066\u3082\u66f4\u65b0\u8ffd\u52a0\u53ef\u80fd\u306b\u3067\u304d\u308b<br \/>\n\u203b \u5217\u6570\u3068\u30ab\u30e9\u30e0\u540d\u3092\u95a2\u9023\u4ed8\u3051\u3000\u203b$i\uff1a\u5217\u6570\u3001$column_1\uff1a\u52171\u306e\u30ab\u30e9\u30e0\u540d<\/li>\n<li>\u914d\u5217\u306e\u4e2d\u8eab\u3092\u53d6\u308a\u3060\u3059\u3002<\/li>\n<li>\u7a7a\u306e\u914d\u5217\u3092\u7528\u610f\u3059\u308b<\/li>\n<li>\u914d\u5217\u756a\u53f7($i)\u3068\u914d\u5217\u30ab\u30e9\u30e0\u540d(${'column'.$i})\u304b\u3089\u9023\u60f3\u914d\u5217\u3092\u4f5c\u6210<\/li>\n<li>\u6587\u5b57\u30b3\u30fc\u30c9\u3092UTF-8\u306b\u5909\u66f4<\/li>\n<li>\u7a7a\u306e\u914d\u5217\u3092\u7528\u610f\u3059\u308b\u3000\u203b\u914d\u5217\u683c\u7d0d\uff1darray\u3001\u60c5\u5831\u8a18\u8f09\u30ab\u30e9\u30e0\u756a\u53f7\u306e\u30ab\u30a6\u30f3\u30c8\uff1dcounts<\/li>\n<li>\u5024\u304c '' \u306e\u5834\u5408\u306f\u98db\u3070\u3059\u3001'NULL'\u306e\u5834\u5408\u306fNULL\u3092\u5165\u308c\u308b<br \/>\n\u203b\u914d\u5217\u21d2\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5909\u63db\u3000$obj = json_decode(json_encode($array));<br \/>\n\u203b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5909\u63db\u3057\u305f\u5834\u5408\u306f $obj-&gt;deliverycost \u3068\u8a18\u8f09\u3057\u3066\u53d6\u5f97<\/li>\n<li>\u5834\u5408\u5206\u3051\u3067\u8aad\u307f\u8fbc\u3080Validation\u3092\u5909\u66f4\u3059\u308b<\/li>\n<li>\u914d\u5217\u3092Validation\u306b\u304b\u3051\u308b\u3002<br \/>\n\u203b Models \u306e\u30eb\u30fc\u30eb\u3092\u547c\u3073\u51fa\u305d\u3046\u3068\u3057\u305f\u304c\u4e0a\u624b\u304f\u52d5\u304b\u306a\u304b\u3063\u305f\u3002<\/li>\n<li>\u30c6\u30fc\u30d6\u30eb\u5185\u3068\u91cd\u8907\u3057\u3066\u3044\u306a\u3044\u304b\u8abf\u67fb\u3002<br \/>\n\u203bwhere\u3067\u62bd\u51fa<br \/>\n\u203b CSV\u3067\u66f4\u65b0\u3057\u305f\u3044\u5024\u306f\u5408\u81f4\u8abf\u67fb\u5bfe\u8c61\u5916\u3002<\/li>\n<li>Where\u3067\u62bd\u51fa\u3055\u308c\u305f\u5834\u5408 save \u4e0a\u66f8\u304d\u51e6\u7406<\/li>\n<li>Where\u3067\u62bd\u51fa\u3055\u308c\u306a\u304b\u3063\u305f\u6642\u306f Insert \u65b0\u898f\u8ffd\u52a0<\/li>\n<\/ol>\n<\/div>\n<p>6\uff5e9\u306fValidation\u306b\u304b\u3051\u308b\u524d\u306e\u4e0b\u6e96\u5099\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\nCSV\u30c7\u30fc\u30bf\u306b\u6b20\u640d\u3084INSERT\/Update\u6df7\u5728\u304c\u3042\u308b\u4e8b\u3092\u8003\u616e\u3059\u308b\u3068\u30d0\u30eb\u30af\u30a4\u30f3\u30b5\u30fc\u30c8\u306f\u4f7f\u3044\u52dd\u624b\u304c\u60aa\u3044\u3068\u5224\u65ad\u3057\u307e\u3057\u305f\u3002<br \/>\n\u305d\u306e\u70ba\u3001\u57fa\u672c\u5b9f\u88c5\u306f1\u4ef6\u3065\u3064\u306e\u66f4\u65b0\u306e\u5f62\u3067\u884c\u3044\u307e\u3057\u305f\u304c\u3001\u30d0\u30eb\u30af\u30a4\u30f3\u30b5\u30fc\u30c8\u306f\u901f\u5ea6\u304c\u901f\u3044\uff01<br \/>\n\u305d\u308c\u3082\u6bb5\u9055\u3044\u306b\uff01<\/p>\n<p>\u3068\u8a00\u3046\u4e8b\u3067\u305d\u308c(\u30d0\u30eb\u30af\u30a4\u30f3\u30b5\u30fc\u30c8)\u7528\u306e\u30d1\u30fc\u30c4\u3082\u4f5c\u3063\u3061\u3083\u3044\u307e\u3057\u305f\u3002<br \/>\n\u878d\u901a\u3068\u901f\u5ea6\u306e\u30c8\u30ec\u30fc\u30c9\u30aa\u30d5\u3067\u3059\u3088\u306d\u3002<\/p>\n<h3>FatController\u3092\u907f\u3051\u308b\u305f\u3081\u30b9\u30af\u30ea\u30d7\u30c8\u3092Model\u306b\u79fb\u3057\u5d4c\u3063\u305f\u30dd\u30a4\u30f3\u30c8<\/h3>\n<p>\u4eca\u56de\u306e\u30b7\u30b9\u30c6\u30e0\u3067\u306f\u3001CSV\u3067\u66f4\u65b0\u3057\u305f\u3044\u9805\u76ee\u304c\u975e\u5e38\u306b\u305f\u304f\u3055\u3093\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u51fa\u6765\u308b\u3060\u3051\u7c21\u5358\u306b\u51e6\u7406\u3057\u3088\u3046\u3068\u601d\u3063\u305f\u6642\u3001\u540c\u3058Controller\u3092\u547c\u51fa\u3057\u3066POST\u3055\u308c\u305f\u5024\u3067\u5834\u5408\u5206\u3051\u3059\u308c\u3070\u3044\u3044\u3058\u3083\u3093\u3068\u306e\u767a\u60f3\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u3053\u306e\u5834\u5408\u5206\u3051\u6bce\u306e\u51e6\u7406\u3092\u540c\u3058\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306b\u8a18\u8f09\u3059\u308b\u3068\u99ac\u9e7f\u30c7\u30c3\u30ab\u30a4Controller\u304c\u51fa\u6765\u4e0a\u304c\u308a\u307e\u3059\u3002\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u6027\u3092\u8003\u3048\u3066\u3082\u3068\u3066\u3082\u559c\u3070\u3057\u3044\u4e8b\u3067\u306f\u306a\u3044\u306e\u3067\u3001DB\u3092\u64cd\u4f5c\u3059\u308b\u7b87\u6240\u306f\u5176\u3005\u306eModel\u306b\u79fb\u305d\u3046\u3068\u8003\u3048\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3053\u3067\u5927\u30cf\u30de\u308a\u306e\u4e8b\u614b\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<p>\u5148\u306b\u7b54\u3048\u3092\u66f8\u304d\u307e\u3059\u3002<\/p>\n<div class=\"borderBox\">\n<ol>\n<li>Varidate\u306e\u5b9f\u884c\u306b\u306fuse\u3067\u5834\u6240\u306e\u6307\u793a\u304c\u5fc5\u8981<br \/>\nuse Illuminate\\Support\\Facades\\Validator;<\/li>\n<li>public static function \u3067\u306f $this \u3067\u306f\u306a\u304f self \u3092\u4f7f\u3046<\/li>\n<\/ol>\n<\/div>\n<p>\u30d6\u30e9\u30a6\u30b6\u30d5\u30a9\u30fc\u30e0\u304b\u3089\u306e\u8ffd\u52a0\/\u66f4\u65b0\u3067\u306f\u554f\u984c\u306a\u304fValidation\u3092\u3057\u3066\u3044\u307e\u3057\u305f\u3057\u3001Controller\u306b\u8a18\u8f09\u3057\u3066\u3044\u305f\u6642\u306b\u3082\u7279\u306b\u6307\u793a\u305b\u305a\u306bValidation\u3092\u4f7f\u3048\u3066\u3044\u307e\u3057\u305f\u3002\u306a\u306e\u3067\u3001\u3059\u3063\u304b\u308a use \u306f\u5fc5\u8981\u306a\u3044\u3068\u601d\u3063\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3053\u308c\u304c\u9593\u9055\u3044\u3067\u3057\u305f\u3002<br \/>\n\u3069\u3046\u3084\u3089Controller\u5074\u304b\u3089Model\u306e\u30d0\u30ea\u30c7\u30fc\u30bf\u3092\u30b3\u30fc\u30eb\u3057\u305f\u6642\u306b\u30a8\u30e9\u30fc\u304c\u8d77\u3053\u3063\u305f\u306e\u3082\u3053\u308c\u304c\u539f\u56e0\u3060\u3063\u305f\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001Model\u306e\u4e2d\u306b\u8a18\u8f09\u3057\u305f\u3010static function\u3011\u3002<br \/>\n\u3053\u306e\u4e2d\u3067\u81ea\u4fe1\u3092\u30b3\u30fc\u30eb\u3059\u308b\u969b\u306b\u306f $this \u3067\u306f\u306a\u304f\u3010self::\u3011\u3092\u4f7f\u3046\u305d\u3046\u3067\u3059\u3002<br \/>\n\u5168\u304f\u7591\u3063\u3066\u306a\u3044\u5834\u6240\u3060\u3063\u305f\u305f\u3081\u767a\u898b\/\u89e3\u6c7a\u307e\u3067\u6642\u9593\u304c\u639b\u304b\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<\/p>\n<h3>\u307e\u3068\u3081<\/h3>\n<p>CSV\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u306b\u3088\u308bupdate\u306b\u3064\u3044\u3066\u306f\u3069\u3046\u51e6\u7406\u3059\u308b\u304b\u3092\u8ffd\u3063\u3066\u3044\u304f\u3053\u3068\u3067\u6ca2\u5c71\u306e\u8a18\u8f09\u65b9\u6cd5\u304c\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u5176\u3005\u306e\u30d1\u30fc\u30c8\u3067\u631f\u307f\u8fbc\u307f\u305f\u3044\u51e6\u7406\u3082\u51fa\u3066\u304f\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u3046\u3044\u3046\u81ea\u7531\u5ea6\u304c\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u9762\u767d\u3044\u6240\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u3055\u3041\u4eca\u65e5\u3082\u9811\u5f35\u308d\u3046\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel\uff1aCSV\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3067MySQL\u3092\u66f4\u65b0\u3059\u308b 2\u9031\u9593\u3076\u308a\u306e\u66f4\u65b0\u3068\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u3053\u306e\u9593\u8272\u3005\u3068\u60a9\u307fTry\uff06Error\u3092\u7e70\u8fd4\u3057\u3066\u307e\u3057\u305f\u3002 \u305d\u306e\u4e2d\u3067\u4ee5\u5916\u306b\u3082\u8d85\u7c21\u5358\u306b\u5b9f\u88c5\u51fa\u6765\u305fCSV\u306b\u3088\u308b\u30c7\u30fc\u30bf\u66f4\u65b0\u306b\u3064\u3044\u3066\u307e\u3068\u3081\u307e\u3059\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":944,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[34],"tags":[48,153,98,53,45],"class_list":["post-1220","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-memorandum","tag-csv","tag-laravel","tag-php","tag-53","tag-45"],"veu_head_title_object":{"title":"","add_site_title":""},"jetpack_publicize_connections":[],"jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/qol-kk.com\/wp2\/wp-content\/uploads\/2018\/11\/laravel_logo.png","_links":{"self":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/1220","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=1220"}],"version-history":[{"count":0,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/1220\/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=1220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/categories?post=1220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/tags?post=1220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}