{"action":"created","comment":{"url":"https://api.github.com/repos/thanhbinhhd/sale-system/pulls/comments/234404721","pull_request_review_id":176050018,"id":234404721,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNDQwNDcyMQ==","diff_hunk":"@@ -31,18 +44,71 @@ public function index()\n      */\n     public function create()\n     {\n-        //\n+        return view('admin.products.create');\n     }\n \n     /**\n-     * Store a newly created resource in storage.\n-     *\n-     * @param  \\Illuminate\\Http\\Request  $request\n-     * @return \\Illuminate\\Http\\Response\n+     * @param CreateProductRequest $request\n+     * @return \\Illuminate\\Http\\RedirectResponse\n      */\n-    public function store(Request $request)\n+    public function store(CreateProductRequest $request)\n     {\n-        //\n+        // kiểm tra có files sẽ xử lý\n+        if($request->hasFile('image')) {\n+            $allowedfileExtension=['jpg','png', 'jpeg'];\n+            $files = array($request->file('image'));\n+            if($request->hasFile('images'))\n+                $files = array_merge($request->file('images'), $files);\n+            // flag xem có thực hiện lưu DB không. Mặc định là có\n+            $exe_flg = true;\n+            // kiểm tra tất cả các files xem có đuôi mở rộng đúng không\n+            foreach($files as $file) {\n+                $extension = $file->getClientOriginalExtension();\n+                $check=in_array($extension,$allowedfileExtension);\n+\n+                if(!$check) {\n+                    // nếu có file nào không đúng đuôi mở rộng thì đổi flag thành false\n+                    $exe_flg = false;\n+                    break;\n+                }\n+            }\n+            // nếu không có file nào vi phạm validate thì tiến hành lưu DB\n+            if($exe_flg) {\n+                // lưu product\n+                $product = $this->product->store(array_merge($request->all(),\n+                        [\n+                            'admin_id' => Auth::guard('admin')->user()->id,\n+                        ]));\n+                $productDetail = $this->detail->store(array_merge($request->all(),\n+                        [\n+                            'product_id' => $product->id,\n+                        ]));\n+                if ($request->has('tag')) {\n+                    foreach ($request->input('tag') as $tag) {\n+                        (new TagRepository(new Tag()))->store([\n+                            'name' => $tag,\n+                            'description' => '',\n+                            'tagable_id' => $product->id,\n+                            'tagable_type' => Product::class\n+                        ]);\n+                    }\n+                }\n+                // duyệt từng ảnh và thực hiện lưu\n+                foreach ($files as $photo) {\n+                    $filename = $photo->store('images/'. $product->category->name);\n+                    (new ImageRepository(new Image()))->store([ // store many file\n+                        'image_url' => $filename,\n+                        'imageable_id' => $product->id,\n+                        'imageable_type' => Product::class,\n+                    ]);\n+                }\n+                \\Session::flash('message', 'Successfully created new \"'. $product->name . '\"!');\n+                return redirect()->route('admin.product-manager.index');\n+            } else {\n+                return back()->withErrors('Failed to upload. Only accept jpg, png, jpeg photos.');","path":"app/Http/Controllers/Admin/ProductController.php","position":114,"original_position":114,"commit_id":"bd7b13dcceef757fa42ab2314305144834675224","original_commit_id":"bd7b13dcceef757fa42ab2314305144834675224","user":{"login":"minhquang4334","id":22545967,"node_id":"MDQ6VXNlcjIyNTQ1OTY3","avatar_url":"https://avatars0.githubusercontent.com/u/22545967?v=4","gravatar_id":"","url":"https://api.github.com/users/minhquang4334","html_url":"https://github.com/minhquang4334","followers_url":"https://api.github.com/users/minhquang4334/followers","following_url":"https://api.github.com/users/minhquang4334/following{/other_user}","gists_url":"https://api.github.com/users/minhquang4334/gists{/gist_id}","starred_url":"https://api.github.com/users/minhquang4334/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minhquang4334/subscriptions","organizations_url":"https://api.github.com/users/minhquang4334/orgs","repos_url":"https://api.github.com/users/minhquang4334/repos","events_url":"https://api.github.com/users/minhquang4334/events{/privacy}","received_events_url":"https://api.github.com/users/minhquang4334/received_events","type":"User","site_admin":false},"body":"các file extension này check trực tiếp trên trong class request truyền vào đc đó","created_at":"2018-11-17T11:02:48Z","updated_at":"2018-11-17T11:02:48Z","html_url":"https://github.com/thanhbinhhd/sale-system/pull/31#discussion_r234404721","pull_request_url":"https://api.github.com/repos/thanhbinhhd/sale-system/pulls/31","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/thanhbinhhd/sale-system/pulls/comments/234404721"},"html":{"href":"https://github.com/thanhbinhhd/sale-system/pull/31#discussion_r234404721"},"pull_request":{"href":"https://api.github.com/repos/thanhbinhhd/sale-system/pulls/31"}}},"pull_request":{"url":"https://api.github.com/repos/thanhbinhhd/sale-system/pulls/31","id":231721208,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMxNzIxMjA4","html_url":"https://github.com/thanhbinhhd/sale-system/pull/31","diff_url":"https://github.com/thanhbinhhd/sale-system/pull/31.diff","patch_url":"https://github.com/thanhbinhhd/sale-system/pull/31.patch","issue_url":"https://api.github.com/repos/thanhbinhhd/sale-system/issues/31","number":31,"state":"open","locked":false,"title":"add feature admin manage product","user":{"login":"hajaulee","id":26093363,"node_id":"MDQ6VXNlcjI2MDkzMzYz","avatar_url":"https://avatars0.githubusercontent.com/u/26093363?v=4","gravatar_id":"","url":"https://api.github.com/users/hajaulee","html_url":"https://github.com/hajaulee","followers_url":"https://api.github.com/users/hajaulee/followers","following_url":"https://api.github.com/users/hajaulee/following{/other_user}","gists_url":"https://api.github.com/users/hajaulee/gists{/gist_id}","starred_url":"https://api.github.com/users/hajaulee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hajaulee/subscriptions","organizations_url":"https://api.github.com/users/hajaulee/orgs","repos_url":"https://api.github.com/users/hajaulee/repos","events_url":"https://api.github.com/users/hajaulee/events{/privacy}","received_events_url":"https://api.github.com/users/hajaulee/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-11-17T10:52:49Z","updated_at":"2018-11-17T11:02:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/thanhbinhhd/sale-system/pulls/31/commits","review_comments_url":"https://api.github.com/repos/thanhbinhhd/sale-system/pulls/31/comments","review_comment_url":"https://api.github.com/repos/thanhbinhhd/sale-system/pulls/comments{/number}","comments_url":"https://api.github.com/repos/thanhbinhhd/sale-system/issues/31/comments","statuses_url":"https://api.github.com/repos/thanhbinhhd/sale-system/statuses/bd7b13dcceef757fa42ab2314305144834675224","head":{"label":"hajaulee:feature-product-admin","ref":"feature-product-admin","sha":"bd7b13dcceef757fa42ab2314305144834675224","user":{"login":"hajaulee","id":26093363,"node_id":"MDQ6VXNlcjI2MDkzMzYz","avatar_url":"https://avatars0.githubusercontent.com/u/26093363?v=4","gravatar_id":"","url":"https://api.github.com/users/hajaulee","html_url":"https://github.com/hajaulee","followers_url":"https://api.github.com/users/hajaulee/followers","following_url":"https://api.github.com/users/hajaulee/following{/other_user}","gists_url":"https://api.github.com/users/hajaulee/gists{/gist_id}","starred_url":"https://api.github.com/users/hajaulee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hajaulee/subscriptions","organizations_url":"https://api.github.com/users/hajaulee/orgs","repos_url":"https://api.github.com/users/hajaulee/repos","events_url":"https://api.github.com/users/hajaulee/events{/privacy}","received_events_url":"https://api.github.com/users/hajaulee/received_events","type":"User","site_admin":false},"repo":{"id":155938095,"node_id":"MDEwOlJlcG9zaXRvcnkxNTU5MzgwOTU=","name":"sale-system","full_name":"hajaulee/sale-system","private":false,"owner":{"login":"hajaulee","id":26093363,"node_id":"MDQ6VXNlcjI2MDkzMzYz","avatar_url":"https://avatars0.githubusercontent.com/u/26093363?v=4","gravatar_id":"","url":"https://api.github.com/users/hajaulee","html_url":"https://github.com/hajaulee","followers_url":"https://api.github.com/users/hajaulee/followers","following_url":"https://api.github.com/users/hajaulee/following{/other_user}","gists_url":"https://api.github.com/users/hajaulee/gists{/gist_id}","starred_url":"https://api.github.com/users/hajaulee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hajaulee/subscriptions","organizations_url":"https://api.github.com/users/hajaulee/orgs","repos_url":"https://api.github.com/users/hajaulee/repos","events_url":"https://api.github.com/users/hajaulee/events{/privacy}","received_events_url":"https://api.github.com/users/hajaulee/received_events","type":"User","site_admin":false},"html_url":"https://github.com/hajaulee/sale-system","description":null,"fork":true,"url":"https://api.github.com/repos/hajaulee/sale-system","forks_url":"https://api.github.com/repos/hajaulee/sale-system/forks","keys_url":"https://api.github.com/repos/hajaulee/sale-system/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hajaulee/sale-system/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hajaulee/sale-system/teams","hooks_url":"https://api.github.com/repos/hajaulee/sale-system/hooks","issue_events_url":"https://api.github.com/repos/hajaulee/sale-system/issues/events{/number}","events_url":"https://api.github.com/repos/hajaulee/sale-system/events","assignees_url":"https://api.github.com/repos/hajaulee/sale-system/assignees{/user}","branches_url":"https://api.github.com/repos/hajaulee/sale-system/branches{/branch}","tags_url":"https://api.github.com/repos/hajaulee/sale-system/tags","blobs_url":"https://api.github.com/repos/hajaulee/sale-system/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hajaulee/sale-system/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hajaulee/sale-system/git/refs{/sha}","trees_url":"https://api.github.com/repos/hajaulee/sale-system/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hajaulee/sale-system/statuses/{sha}","languages_url":"https://api.github.com/repos/hajaulee/sale-system/languages","stargazers_url":"https://api.github.com/repos/hajaulee/sale-system/stargazers","contributors_url":"https://api.github.com/repos/hajaulee/sale-system/contributors","subscribers_url":"https://api.github.com/repos/hajaulee/sale-system/subscribers","subscription_url":"https://api.github.com/repos/hajaulee/sale-system/subscription","commits_url":"https://api.github.com/repos/hajaulee/sale-system/commits{/sha}","git_commits_url":"https://api.github.com/repos/hajaulee/sale-system/git/commits{/sha}","comments_url":"https://api.github.com/repos/hajaulee/sale-system/comments{/number}","issue_comment_url":"https://api.github.com/repos/hajaulee/sale-system/issues/comments{/number}","contents_url":"https://api.github.com/repos/hajaulee/sale-system/contents/{+path}","compare_url":"https://api.github.com/repos/hajaulee/sale-system/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hajaulee/sale-system/merges","archive_url":"https://api.github.com/repos/hajaulee/sale-system/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hajaulee/sale-system/downloads","issues_url":"https://api.github.com/repos/hajaulee/sale-system/issues{/number}","pulls_url":"https://api.github.com/repos/hajaulee/sale-system/pulls{/number}","milestones_url":"https://api.github.com/repos/hajaulee/sale-system/milestones{/number}","notifications_url":"https://api.github.com/repos/hajaulee/sale-system/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hajaulee/sale-system/labels{/name}","releases_url":"https://api.github.com/repos/hajaulee/sale-system/releases{/id}","deployments_url":"https://api.github.com/repos/hajaulee/sale-system/deployments","created_at":"2018-11-03T01:17:11Z","updated_at":"2018-11-03T01:17:14Z","pushed_at":"2018-11-17T10:52:24Z","git_url":"git://github.com/hajaulee/sale-system.git","ssh_url":"git@github.com:hajaulee/sale-system.git","clone_url":"https://github.com/hajaulee/sale-system.git","svn_url":"https://github.com/hajaulee/sale-system","homepage":null,"size":2827,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"thanhbinhhd:master","ref":"master","sha":"76c01ef1c26dd5c25e785c56f41529a126c37c96","user":{"login":"thanhbinhhd","id":30487118,"node_id":"MDQ6VXNlcjMwNDg3MTE4","avatar_url":"https://avatars3.githubusercontent.com/u/30487118?v=4","gravatar_id":"","url":"https://api.github.com/users/thanhbinhhd","html_url":"https://github.com/thanhbinhhd","followers_url":"https://api.github.com/users/thanhbinhhd/followers","following_url":"https://api.github.com/users/thanhbinhhd/following{/other_user}","gists_url":"https://api.github.com/users/thanhbinhhd/gists{/gist_id}","starred_url":"https://api.github.com/users/thanhbinhhd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thanhbinhhd/subscriptions","organizations_url":"https://api.github.com/users/thanhbinhhd/orgs","repos_url":"https://api.github.com/users/thanhbinhhd/repos","events_url":"https://api.github.com/users/thanhbinhhd/events{/privacy}","received_events_url":"https://api.github.com/users/thanhbinhhd/received_events","type":"User","site_admin":false},"repo":{"id":154780861,"node_id":"MDEwOlJlcG9zaXRvcnkxNTQ3ODA4NjE=","name":"sale-system","full_name":"thanhbinhhd/sale-system","private":false,"owner":{"login":"thanhbinhhd","id":30487118,"node_id":"MDQ6VXNlcjMwNDg3MTE4","avatar_url":"https://avatars3.githubusercontent.com/u/30487118?v=4","gravatar_id":"","url":"https://api.github.com/users/thanhbinhhd","html_url":"https://github.com/thanhbinhhd","followers_url":"https://api.github.com/users/thanhbinhhd/followers","following_url":"https://api.github.com/users/thanhbinhhd/following{/other_user}","gists_url":"https://api.github.com/users/thanhbinhhd/gists{/gist_id}","starred_url":"https://api.github.com/users/thanhbinhhd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thanhbinhhd/subscriptions","organizations_url":"https://api.github.com/users/thanhbinhhd/orgs","repos_url":"https://api.github.com/users/thanhbinhhd/repos","events_url":"https://api.github.com/users/thanhbinhhd/events{/privacy}","received_events_url":"https://api.github.com/users/thanhbinhhd/received_events","type":"User","site_admin":false},"html_url":"https://github.com/thanhbinhhd/sale-system","description":null,"fork":false,"url":"https://api.github.com/repos/thanhbinhhd/sale-system","forks_url":"https://api.github.com/repos/thanhbinhhd/sale-system/forks","keys_url":"https://api.github.com/repos/thanhbinhhd/sale-system/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thanhbinhhd/sale-system/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thanhbinhhd/sale-system/teams","hooks_url":"https://api.github.com/repos/thanhbinhhd/sale-system/hooks","issue_events_url":"https://api.github.com/repos/thanhbinhhd/sale-system/issues/events{/number}","events_url":"https://api.github.com/repos/thanhbinhhd/sale-system/events","assignees_url":"https://api.github.com/repos/thanhbinhhd/sale-system/assignees{/user}","branches_url":"https://api.github.com/repos/thanhbinhhd/sale-system/branches{/branch}","tags_url":"https://api.github.com/repos/thanhbinhhd/sale-system/tags","blobs_url":"https://api.github.com/repos/thanhbinhhd/sale-system/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thanhbinhhd/sale-system/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thanhbinhhd/sale-system/git/refs{/sha}","trees_url":"https://api.github.com/repos/thanhbinhhd/sale-system/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thanhbinhhd/sale-system/statuses/{sha}","languages_url":"https://api.github.com/repos/thanhbinhhd/sale-system/languages","stargazers_url":"https://api.github.com/repos/thanhbinhhd/sale-system/stargazers","contributors_url":"https://api.github.com/repos/thanhbinhhd/sale-system/contributors","subscribers_url":"https://api.github.com/repos/thanhbinhhd/sale-system/subscribers","subscription_url":"https://api.github.com/repos/thanhbinhhd/sale-system/subscription","commits_url":"https://api.github.com/repos/thanhbinhhd/sale-system/commits{/sha}","git_commits_url":"https://api.github.com/repos/thanhbinhhd/sale-system/git/commits{/sha}","comments_url":"https://api.github.com/repos/thanhbinhhd/sale-system/comments{/number}","issue_comment_url":"https://api.github.com/repos/thanhbinhhd/sale-system/issues/comments{/number}","contents_url":"https://api.github.com/repos/thanhbinhhd/sale-system/contents/{+path}","compare_url":"https://api.github.com/repos/thanhbinhhd/sale-system/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thanhbinhhd/sale-system/merges","archive_url":"https://api.github.com/repos/thanhbinhhd/sale-system/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thanhbinhhd/sale-system/downloads","issues_url":"https://api.github.com/repos/thanhbinhhd/sale-system/issues{/number}","pulls_url":"https://api.github.com/repos/thanhbinhhd/sale-system/pulls{/number}","milestones_url":"https://api.github.com/repos/thanhbinhhd/sale-system/milestones{/number}","notifications_url":"https://api.github.com/repos/thanhbinhhd/sale-system/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thanhbinhhd/sale-system/labels{/name}","releases_url":"https://api.github.com/repos/thanhbinhhd/sale-system/releases{/id}","deployments_url":"https://api.github.com/repos/thanhbinhhd/sale-system/deployments","created_at":"2018-10-26T05:15:59Z","updated_at":"2018-11-17T07:08:50Z","pushed_at":"2018-11-17T10:52:49Z","git_url":"git://github.com/thanhbinhhd/sale-system.git","ssh_url":"git@github.com:thanhbinhhd/sale-system.git","clone_url":"https://github.com/thanhbinhhd/sale-system.git","svn_url":"https://github.com/thanhbinhhd/sale-system","homepage":null,"size":9369,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":2,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/thanhbinhhd/sale-system/pulls/31"},"html":{"href":"https://github.com/thanhbinhhd/sale-system/pull/31"},"issue":{"href":"https://api.github.com/repos/thanhbinhhd/sale-system/issues/31"},"comments":{"href":"https://api.github.com/repos/thanhbinhhd/sale-system/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/thanhbinhhd/sale-system/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/thanhbinhhd/sale-system/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/thanhbinhhd/sale-system/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/thanhbinhhd/sale-system/statuses/bd7b13dcceef757fa42ab2314305144834675224"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"minhquang4334"}}