public function save($id, ProductSaveRequest $request) { $product = $this->productRepository->getById($id); if (!$product) { $product = new AmazonProduct(); } $product->fill($request->all()); Auth::user()->products()->save($product); return $this->json->success('Product Saved Successfully ...'); }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { $id = $this->route('id'); if ($id == 0) { return TRUE; } return \Auth::user()->owns(\App\AmazonProduct::find($id)); }
public function view($id) { $review = $this->customerReviewRepository->getById($id); if (!$review) { $review = new CustomerReview(); $review->id = 0; } $products = AmazonProduct::all(); $customers = Customer::where('user_id', '=', auth()->user()->id)->get(); $content = View::make('reviews.modals.view', compact('review', 'products', 'customers'))->render(); return $this->json->set('content', $content)->success(); }
public function processReviews(Request $request) { $data = $request->get('reviews'); $fileContents = trim($data); if (empty($fileContents)) { return $this->json->error('Paste Box Must Not Be Empty ...'); } $fileLines = explode("\r\n", $fileContents); $fileLines = explode("\r", $fileContents); $maxLineCount = count($fileLines); $user = Auth::user(); for ($x = 0; $x < $maxLineCount; $x++) { $url = $fileLines[$x]; $urlExploded = explode('/', $url); $urlArray = parse_url($url); if (!is_array($urlArray) or !isset($urlArray['query'])) { continue; } $buyerId = $urlExploded[5]; parse_str($urlArray['query'], $query); $sku = $query['ASIN']; $sku = str_replace('-', '', $sku); $customer = Customer::whereBuyerId($buyerId)->first(); if (!$customer) { continue; } $product = AmazonProduct::whereSku($sku)->first(); if (!$product) { continue; } $customerReview = CustomerReview::where('customer_id', '=', $customer->id)->where('amazon_product_id', '=', $product->id)->first(); if ($customerReview) { continue; } $customerReview = new CustomerReview(); $customerReview->customer_id = $customer->id; $customerReview->amazon_product_id = $product->id; $customerReview->link = $url; $customerReview->save(); } return $this->json->success('SUCCESS!!! Import data done ....'); }