public function loadTable()
 {
     $products = Product::orderBy('name', 'asc')->with('category')->get();
     $products->updated_at = '100';
     $products_f = ['data' => $products];
     echo json_encode($products_f);
 }
 public function getAdd(Request $request)
 {
     $lastProduct = Product::orderBy('created_at', 'DESC')->first();
     $perpage = 12;
     $imgs = Img::where('img_block', '=', 'public')->orderBy('created_at', 'DESC')->simplePaginate($perpage);
     return view('manage.product.add', ['TITLE' => '新增商品', 'META_KEYWORDS' => META_KEYWORDS, 'META_DESC' => META_DESC, 'PAGE_CODE' => '/manage/product/add', 'lastProduct' => $lastProduct, 'imgs' => $imgs]);
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $products = Product::orderBy('name', 'asc')->paginate();
     $products->setPath(route('products.index'));
     //dd($products);
     return view("products.lista", compact('products'));
 }
 /**
  * Save a new snapshot.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $snapshotUrl = $request->file('snapshot_url');
     if ($snapshotUrl) {
         $filename = time() . '.' . $snapshotUrl->getClientOriginalExtension();
         $filepath = '/snapshots/' . $filename;
         if (!Storage::disk('s3')->put($filepath, file_get_contents($snapshotUrl), 'public')) {
             $filename = '';
         }
     }
     $this->validate($request, ['store_id' => 'required']);
     if (!$request->id) {
         $snapshot = Snapshot::create(['store_id' => $request->store_id, 'notes' => $request->notes, 'snapshot_url' => isset($filepath) ? $filepath : '']);
     } else {
         $snapshot = Snapshot::find($request->id);
         $snapshot->store_id = $request->store_id;
         $snapshot->notes = $request->notes;
         if ($snapshotUrl) {
             $snapshot->snapshot_url = $filepath;
         }
         $snapshot->save();
     }
     $for_sale = Product::orderBy('name')->where('store_id', $request->store_id)->where('product_status', 1)->get();
     foreach ($for_sale as $item) {
         $snapshot->products()->attach($item->id);
     }
     return redirect('/snapshot');
 }
 public function getIndex()
 {
     $posts = Post::orderBy('created_at', 'desc')->take(5)->get();
     $products = Product::orderBy('created_at', 'desc')->take(5)->get();
     $references = Reference::orderBy('created_at', 'desc')->take(5)->get();
     return view('admin/index', ['posts' => $posts, 'products' => $products, 'references' => $references]);
 }
Example #6
0
 /**
  * Display the details and order form of a product
  *
  * @param $id
  * @param string $slug
  */
 public function showProduct($id, $slug = '')
 {
     $bests = Product::orderBy('score', 'desc')->orderBy('price', 'desc')->take(4)->get();
     $product = Product::findOrFail($id);
     $title = "Product {$product->name}";
     return view('front.prod', compact('product', 'bests', 'title', 'customer_id'));
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $products = Product::orderBy('priority')->get();
     if ($request->ajax()) {
         return $products->toArray();
     }
     return view('admin.products.index', ['products' => $products]);
 }
 public function productManagement()
 {
     $page = 'partials.admin-productManagement';
     $users = User::all();
     $products = Product::orderBy('created_at', 'desc')->paginate(8);
     $products->setPath('');
     return view('quantri/admin', compact('page', 'users', 'products'));
 }
Example #9
0
 public function index($id = null)
 {
     if ($id == null) {
         return Product::orderBy('id', 'asc')->get();
     } else {
         return $this->show($id);
     }
 }
 public function home()
 {
     if ($this->isCrawler()) {
         $products = Product::orderBy('created_at', 'desc')->limit(20)->get();
         return view('crawler.home', ['products' => $products]);
     } else {
         return view('beta');
     }
 }
 public function index()
 {
     $count_hodon = Hoadon::count();
     $count_sanpham = Product::count();
     $count_danhgia = Danhgia::count();
     $product = Product::orderBy('id', 'DESC')->take(3)->get()->toArray();
     $donhang = Hoadon::orderBy('id', 'DESC')->take(4)->get();
     return view('backend.home', compact('count_hodon', 'count_sanpham', 'count_danhgia', 'product', 'donhang'));
 }
 public function products(Request $request)
 {
     if ($request->sort && $request->orderby) {
         $products = Product::orderBy($request->sort, $request->orderby)->paginate(15);
     } else {
         $products = Product::orderBy('created_at', 'desc')->paginate(15);
     }
     return view('admin.products', compact('products'));
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $page = $request->input('page', null);
     $perpage = 10;
     $skip = ($page - 1) * $perpage;
     $orderBy = $request->input('sort', null) == 'DESC' ? 'DESC' : 'ASC';
     $products = Product::orderBy('name', $orderBy)->skip($skip)->take($perpage)->get()->toArray();
     return Response::json(array('error' => false, 'products' => $products), 200);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $sliders = Slider::all();
     $categories = Category::all();
     $products = Product::orderBy('id', 'desc')->take(12)->get();
     $discount_products = Product::where('discount', '=', 'true')->take(12)->get();
     $random_products = Product::orderByRaw("RAND()")->take(10)->get();
     return view('home', compact('sliders', 'categories', 'products', 'discount_products', 'random_products'));
 }
Example #15
0
 public function postSearch()
 {
     $products = Product::orderBy('id', 'DESC')->paginate(25);
     $categories = new Category();
     $categoryAll = $categories->getCategoriesDropDown();
     $category_id = Input::get('category_id');
     $product_id = Input::get('product_id');
     $productsName = Product::where('category_id', '=', $category_id)->where('id', '=', $product_id)->get();
     return view('Products.list', compact('products'))->with('categoryAll', $categoryAll)->with('productsName', $productsName);
 }
Example #16
0
 /**
  * Show the application welcome screen to the user.
  *
  * @return Response
  */
 public function index(Request $request)
 {
     if ($request->has('q')) {
         $q = $request->get('q');
         $products = Product::where('name', 'like', "%{$q}%")->orWhere('sku', 'like', "%{$q}%")->orWhere('price', 'like', "%{$q}%")->orWhere('tags', 'like', "%{$q}%")->paginate(15);
     } else {
         //$products = Product::all();
         $products = Product::orderBy('id', 'desc')->paginate(15);
     }
     return view('admin.products.index')->with('products', $products);
 }
 public function view_products()
 {
     $data = [];
     if (Product::count() > 0) {
         $data['results'] = Product::orderBy('caption', 'asc')->get();
         return response()->json($data, 200);
     } else {
         $data['results'] = "No data fund";
         return response()->json($data, 404);
     }
 }
 public function index()
 {
     $new_products = Product::orderBy('created_at', 'desc')->take(12)->get();
     $get_best_sellers = App\OrderProduct::select('product_id', \DB::raw('COUNT(product_id) as count'))->groupBy('product_id')->orderBy('count', 'desc')->take(8)->get();
     $best_sellers = [];
     foreach ($get_best_sellers as $product) {
         $best_sellers[] = $product->product;
     }
     helperFunctions::getPageInfo($sections, $cart, $total);
     return view('site.index', compact('new_products', 'best_sellers', 'sections', 'cart', 'total'));
 }
 public function showAllProducts()
 {
     $user = Auth::user();
     if ($user != null && $user->hasRole('admin')) {
         $products = Product::orderBy('created_at', 'DESC')->orderBy('votes', 'DESC')->paginate(10);
         $products = Product::add_created_by_and_category($products);
         return view('admin.products')->with('allproducts', $products);
     } else {
         return view('admin.login');
     }
 }
Example #20
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $limit = Input::get('limit') ? Input::get('limit') : 10;
     $query = Input::get('q');
     if ($query) {
         $products = Product::where('product_code', 'LIKE', "%{$query}%")->simplePaginate($limit);
     } else {
         $products = Product::orderBy('id', 'desc')->simplePaginate($limit);
         #orderBy('added_time','desc')->
     }
     return view('product.index', compact(['products', 'query']));
 }
 public function index(Request $request)
 {
     //search query
     if ($request->get('query')) {
         $this->validate($request, ['query' => 'required']);
         $search = $request->get('query');
         $products = Product::orderBy('name', 'asc')->where('name', 'LIKE', '%' . $search . '%')->get();
         return view('product.index', compact('products'));
     }
     $products = Product::orderBy('name', 'asc')->get();
     return view('product.index', compact('products'));
 }
 public function ProductOfCate($slug)
 {
     $cate_id = Category::where('slug', '=', $slug)->first();
     $categories = Category::all();
     $productOfcate = Product::where('category_id', $cate_id->id)->orderBy('created_at', 'DESC')->get();
     $featured_products = FeaturedProduct::orderBy('rank', 'ASC')->get();
     foreach ($featured_products as $i) {
         $id[] = $i->product_id;
     }
     $featured_photo = Photo::whereIn('product_id', $id)->get();
     $lastest_product = Product::orderBy('created_at', 'DESC')->limit(8)->get();
     return view('pages.category', compact('productOfcate', 'cate_id', 'categories', 'featured_products', 'featured_photo', 'lastest_product'));
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table('products', function (Blueprint $table) {
         $table->integer('source_id')->default(0);
     });
     // update all of the products to have the source id of their purchase
     $products = Product::orderBy('name', 'asc')->get();
     foreach ($products as $product) {
         if ($product->purchase && $product->purchase->source_id > 0) {
             $product->source_id = $product->purchase->source_id;
             $product->save();
         }
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     //
     //        return view("wd.admin.product.index")->withData([
     //            'products' => Product::orderBy('created_at', 'desc')->paginate(16),
     //            'keywords' => '',
     //        ]);
     $keywords = Input::get('keywords');
     if (is_null($keywords) || $keywords == '') {
         return view("wd.admin.product.index")->withData(['products' => Product::orderBy('created_at', 'desc')->paginate(16), 'keywords' => '']);
     } else {
         return view("wd.admin.product.index")->withData(['products' => Product::where('name', 'like', '%' . $keywords . '%')->orderBy('created_at', 'desc')->paginate(16), 'keywords' => $keywords]);
     }
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     view()->composer('*', function ($view) {
         $maxPrice = Product::orderBy('price', 'DESC')->first()->price;
         $minPrice = Product::orderBy('price', 'ASC')->first()->price;
         $colors = Color::all();
         $types = Type::all();
         $heartBag = User::getHeartBag();
         if (Auth::check()) {
             $view->with('bagContent', Auth::user()->bags->where('inBag', 1))->with('colors', $colors)->with('types', $types)->with('maxPrice', $maxPrice)->with('minPrice', $minPrice)->with('heartBag', $heartBag);
         } else {
             $view->with('bagContent', 0)->with('heartBag', 0)->with('minPrice', $minPrice)->with('maxPrice', $maxPrice)->with('colors', $colors)->with('types', $types);
         }
     });
 }
Example #26
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $limit = $request->get('limit', 10);
     //     	$products = Cache::remember('products', 15/60, function() use($limit) {
     //     		return Product::orderBy('created_at', 'desc')->paginate($limit);
     // 			return Product::all();
     //     	});
     $products = Product::orderBy('created_at', 'desc')->paginate($limit);
     // trigger to expose all the variants
     foreach ($products as $product) {
         $product->channels;
         foreach ($product->variants as $variant) {
             $variant->channels;
         }
     }
     return response()->json(array_merge($products->toArray(), ['code' => 200]), 200);
 }
Example #27
0
 public function statistics()
 {
     // Getting data about top 3 products
     $products = App\Product::orderBy('clicks', 'desc')->limit(3)->select(['id', 'item_id', 'clicks', 'views'])->get()->toArray();
     foreach ($products as $key => $product) {
         $products[$key]['img'] = App\Product::find($product['id'])->images()->first()->toArray()['url'];
     }
     // Total clicks and earned money
     $total['clicks'] = App\Product::sum('clicks');
     $total['earned'] = 0;
     // Getting data about shops + clicks per shop
     $shops_query = App\Shop::orderBy('name', 'desc')->select(['id', 'name', 'earned'])->get();
     $shops = [];
     foreach ($shops_query as $shop) {
         $shops[] = ['id' => $shop->id, 'name' => $shop->name, 'earned' => $shop->earned, 'clicks' => round(App\Product::where('shop_id', '=', $shop->id)->sum('clicks'), 2)];
         $total['earned'] += $shop->earned;
     }
     return \View::make('admin/statistics', ['title' => 'Statistiky', 'top_products' => $products, 'shops' => $shops, 'total' => $total]);
 }
Example #28
0
 public function postIndex(Request $request, $pid, $mode)
 {
     if ($mode == 'Delete') {
         // use DB facade to delete the row matching $pid
         \App\Product::destroy($pid);
         $request->session()->flash('message', 'Product ID ' . $request->input('productID') . ' Deleted');
     } else {
         // validate that the product ID is at least 5 characters
         $this->validate($request, ['productID' => 'required|min:5', 'productName' => 'required|min:5', 'category' => 'required', 'price' => 'required|numeric|min:3|max:100000', 'discount' => 'required|numeric|min:0|max:30', 'active' => 'required']);
         // create a model and set the values, then session_save_path
         if ($mode == 'Edit') {
             // get the model from the db
             $products = \App\Product::where('id', '=', $pid)->get();
             $product = $products->first();
         } else {
             // instantiate a new model
             $product = new \App\Product();
         }
         // now set the model attributes
         $product->product_id = $request->input('productID');
         $product->product_name = $request->input('productName');
         $product->category_id = $request->input('category');
         $product->price = $request->input('price');
         $product->max_discount = $request->input('discount');
         $product->active = $request->input('active');
         if ($mode == 'Edit') {
             $product->id = $pid;
         }
         $product->save();
         $request->session()->flash('message', 'Product ID ' . $product->product_id . ' Updated / Added');
     }
     $pcol = $request->session()->get('pcol');
     $pord = $request->session()->get('pord');
     $pord = $pord == 'A' ? 'D' : 'A';
     $request->session()->put('pord', $pord);
     // need to refresh the products collection after changes
     $products = \App\Product::orderBy('product_name')->get();
     // now put the collection in the session variable
     $request->session()->put('products', $products);
     // now direct to the sort route to retain the sort the user had before editing
     return redirect('products/sort/' . $pcol);
 }
Example #29
0
 public function postIndex(Request $request)
 {
     // first retrieve the product catalog
     $products = \App\Product::orderBy('product_name')->get();
     // now filter the collection as needed based on user input
     //first filter on name / id if user entered a string
     $pmatch = strtolower($request->input('product'));
     if (isset($pmatch) && $pmatch != '') {
         $filtered = $products->filter(function ($item) use($pmatch) {
             return is_int(strpos(strtolower($item->product_name), $pmatch)) || is_int(strpos(strtolower($item->product_id), $pmatch));
         });
         $products = $filtered;
     }
     //now filter on active if not set to "Both"
     $active = $request->input('active');
     if ($active == 1) {
         // show only active
         $filtered = $products->filter(function ($item) {
             return $item->active == 1;
         });
         $products = $filtered;
     } elseif ($active == 0) {
         // show only active
         $filtered = $products->filter(function ($item) {
             return $item->active == 0;
         });
         $products = $filtered;
     }
     // now filter by category
     $cat = $request->input('cat');
     if (isset($cat) && $cat > 0) {
         $filtered = $products->filter(function ($item) use($cat) {
             return $item->category_id == $cat;
         });
         $products = $filtered;
     }
     // now return the view with the filtered list
     $request->session()->put('products', $products);
     $pcol = $request->session()->get('pcol');
     return view('products', ['sortOrder' => $pcol], ['products' => $products]);
 }
Example #30
0
 /**
  * Returns products based on given filters
  *
  * @param string regex
  * @return json result
  */
 public function loadProducts(Request $request)
 {
     if ($request->isMethod('post')) {
         if (null == ($order = explode("-", $request->order)) || count($order) != 2) {
             $order = ['views', 'desc'];
         }
         $query = App\Product::orderBy($order[0], $order[1]);
         if (null != ($pattern = urldecode($request->input('pattern')))) {
             $query->where('product_name', 'regexp', $pattern);
         }
         if (null != ($min = $request->input('min')) && null != ($max = $request->input('max'))) {
             $query->where('price', '>=', $min)->where('price', '<=', $max);
         }
         if (null != ($section = urldecode($request->input('section')))) {
             $query->where('section_id', $section);
         }
         $products = $query->skip((int) $request->input('offset'))->take((int) $request->input('limit'))->get()->toArray();
         foreach ($products as $key => $product) {
             $products[$key]['img'] = App\Product::find($product['id'])->images()->first()->toArray()['url'];
         }
         return json_encode($products);
     }
     return '403';
 }