/**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $product = Products::find($id);
     if (is_null($product)) {
         abort(404);
     }
     return view('pages.single', compact('product'));
 }
 public function edit(Request $request, $id)
 {
     $user = $request->user();
     $product = Products::find($id);
     if ($user->id != $product->author_id and $user->is_admin() == false and $user->is_moderator() == false) {
         return redirect('/')->withErrors('You have not sufficient permissions ');
     }
     $categories = Categories::all();
     return view('product.edit')->withProduct($product)->withCategories($categories);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $pro = Products::find($id);
     $this->changeColsToOutFormat($pro);
     return response()->json($pro);
 }
Ejemplo n.º 4
0
 public function predictStock($id)
 {
     $product = Products::find($id);
     $content = Products::find($id)->content;
     $mini = 100000;
     foreach ($content as $key => $value) {
         $count = (int) $value->count;
         $material = $value->material;
         if ($mini > (int) $material->stock / $count) {
             $mini = floor((int) $material->stock / $count);
         }
     }
     return response()->json(["max_count" => $mini]);
 }
Ejemplo n.º 5
0
 public function ProductGetDelete($id)
 {
     $product = Products::find($id);
     $img = [$product->img1, $product->img2, $product->img3, $product->img4];
     $this->deleteImage($img);
     $product->delete();
     return redirect()->route("admin.product.list")->with("result", "Xóa thành công");
 }
 public function delete(Request $request)
 {
     if (!ACL::hasPermission('products', 'delete')) {
         return redirect(route('products'))->withErrors(['Você não pode deletar produtos.']);
     }
     if ($request->image != "") {
         if (File::exists($this->folder . $request->image)) {
             File::delete($this->folder . $request->image);
         }
     }
     Products::find($request->get('productsId'))->delete();
     $success = "Produto excluído com sucesso.";
     return redirect(route('products'))->with(compact('success'));
 }
 public function viewProduct($id)
 {
     $product = Products::find($id);
     return \View::make('/product/viewone')->with('product', $product)->with('title', 'Product');
 }
Ejemplo n.º 8
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $product = Products::find($id);
     return view('productdetails', compact('product'));
 }
 public function deleteEntity(Request $request, Response $response)
 {
     $validator = Validator::make($request->all(), ['id' => 'required|numeric']);
     if ($validator->fails()) {
         $response->header(Constants::RESPONSE_HEADER, "\"id\" query parameter is required and must contain number as value.");
         $response->setStatusCode(Response::HTTP_UNPROCESSABLE_ENTITY);
         return $response;
     }
     $id = $request->input("id");
     $product = Products::find($id);
     DB::beginTransaction();
     $isFileDeleted = $this->persistenceHelper->deleteImageByName($product->image_name);
     if ($isFileDeleted === false) {
         DB::rollBack();
         $response->header(Constants::RESPONSE_HEADER, "Failed to delete previous file.");
         $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
         return $response;
     }
     $isProductDeleted = $product->delete();
     if ($isProductDeleted === false) {
         DB::rollBack();
         $response->header(Constants::RESPONSE_HEADER, "Failed to delete previous file.");
         $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
         return $response;
     }
     DB::commit();
     $response->header(Constants::RESPONSE_HEADER, "Successfully deleted product entry.");
     $response->setStatusCode(Response::HTTP_NO_CONTENT);
     return $response;
 }
 public function getSingleStudent($id)
 {
     return Products::find($id);
 }
Ejemplo n.º 11
0
 public function update2(ProductsRequest $request, $id)
 {
     $product = Products::find($id);
     $product->name = $request->get('name');
     $product->description = $request->get('description');
     if (Input::hasFile('image') && Input::file('image')->isValid()) {
         $path = public_path() . '/images/products/' . $id . '/';
         if (!is_dir($path)) {
             mkdir($path);
         }
         $destination_path = $path;
         $extension = Input::file('image')->getClientOriginalExtension();
         $file_name = 'products_' . $id . '.' . $extension;
         $upload_success = Input::file('image')->move($destination_path, $file_name);
         if ($upload_success) {
             $product->image = '/images/products/' . $id . '/' . $file_name;
         }
     }
     $product->save();
     return redirect()->route('products');
 }
 public function indexPhones()
 {
     $crawler = new Crawler();
     //-------------extract all product details------------------
     global $products;
     $products = array();
     $html = file_get_contents('http://www.mudah.my/Malaysia/Mobile-Phones-and-Gadgets-for-sale-3020?lst=0&fs=1&cg=3020&w=3&so=1&st=s&categorylevel_one=1');
     $crawler->addContent($html);
     //------------------filter category-------------------------------------------------------------
     $toReplace = array('Item Type', 'Tablets', 'Repair/Servicing', 'Others');
     $with = array('', '', '', '');
     $category = str_replace($toReplace, $with, $crawler->filter('select#categorylevel_one')->text());
     //-----------------------------------------------------------------------------------------------
     $crawler->filter('div.listing_thumbs')->each(function ($crawler) {
         for ($i = 2; $i <= 5;) {
             $url = 'http://www.mudah.my/Malaysia/Mobile-Phones-and-Gadgets-for-sale-3020?o=' . $i . '&categorylevel_one=1&q=&so=1&th=1';
             $html = file_get_contents($url);
             $crawler->addContent($html);
             global $rank;
             global $products;
             $rank = $crawler->filter('h2.list_title.truncate a')->each(function ($crawler, $i) use(&$products) {
                 $products[$i]['title'] = $crawler->text();
                 $products[$i]['url'] = $crawler->attr('href');
             });
             $rank = $crawler->filter('div.ads_price')->each(function ($crawler, $i) use(&$products) {
                 $toReplace = array(' ', 'RM');
                 $with = array('', '');
                 $products[$i]['price'] = str_replace($toReplace, $with, $crawler->text());
             });
             $rank = $crawler->filter('li.listing_thumbs_image img')->each(function ($crawler, $i) use(&$products) {
                 $products[$i]['image'] = $crawler->attr('src');
             });
             $rank = $crawler->filter('div.location')->each(function ($crawler, $i) use(&$products) {
                 $products[$i]['location'] = str_replace(' ', '', $crawler->children()->siblings()->text());
             });
             $rank = $crawler->filter('div[title="Condition"]')->each(function ($crawler, $i) use(&$products) {
                 $products[$i]['condition'] = $crawler->text();
             });
             ++$rank;
             $i++;
             //print_r($products);
         }
     });
     //--------------insert data using model-----------------
     foreach ($products as $pro) {
         if ($category == 'Phones') {
             $category_id = 1;
         }
         $arrProduct = explode(' ', $pro['title']);
         $brands = \DB::table('brand')->whereIn('brand_title', $arrProduct)->get();
         if ($brands) {
             foreach ($brands as $brand) {
                 $brand_id = $brand->id;
             }
         } else {
             $brand_id = 21;
         }
         $product_name = $pro['title'];
         $shopper_link = $pro['url'];
         $product_price = $pro['price'];
         $picture_link = str_replace('thumbs', 'images', $pro['image']);
         $product_location = $pro['location'];
         if ($pro['condition'] == 'New') {
             $condition_id = 1;
         } else {
             $condition_id = 2;
         }
         $product_id = 0;
         $productExistFilter = $this->productExistFilter($product_name, $shopper_link, $picture_link, $brand_id, $product_id);
         if ($productExistFilter) {
             //this if $productExistFilter return true......will update product from database
             if ($product_id !== 0) {
                 $product = Products::find($product_id);
                 $product_price_temp = $product->product_price;
                 $product->product_price = $product_price;
                 $product->product_price_temp = $product_price_temp;
                 $product->save();
             }
         } else {
             //this if $productExistFilter return false........will create new product to database...
             // $product = new Products;
             // $product->product_name = $product_name;
             // $product->product_price = $product_price;
             // $product->product_price_temp = $product_price;
             // $product->product_location = $product_location;
             // $product->picture_link = $picture_link;
             // $product->shopper_link = $shopper_link;
             // $product->category_id = $category_id;
             // $product->brand_id = $brand;
             // $product->condition_id = $condition_id;
             // 		$product->save();
         }
     }
     //--------------------------------------------------------
     return "<div class='alert alert-success'>Successfully crawler site</div>";
 }