/** * Display product's details page. * * @param $product * * @return Response */ public function product($product) { $categories = Category::get()->sortBy('name'); $paginate = Product::paginate(6); $products = $paginate->items(); $product = Product::findByName($product)->get()->first(); return view('product.index', compact('product', 'products', 'categories')); }
/** * Execute the command. * * @param Request $request */ public function handle(Request $request) { $client = new GoutteClient(); $slug = $request->input('slug'); $categories = $request->input('categories'); $crawler = $client->request('GET', self::BASE_URL . '/' . $slug); $products = $this->getProducts($crawler); foreach ($products as $product) { if ($this->saveProductImage($client, $product['url'], $product['slug'], $product['ext'])) { $product = Product::create(['name' => $product['item'], 'image' => $product['slug'] . '.' . $product['ext'], 'description' => $product['item'], 'price' => $product['price'], 'status' => 0, 'quantity' => 0]); foreach ($categories as $category) { $product->category()->attach($category); } } } }
/** * Delete Product. * * @param int $id * * @return Response */ public function destroy($id) { $product = Product::findOrFail($id); $product->destroy(); }
public function products() { return Product::all(); }