/** * Execute the console command. * * @return mixed */ public function handle() { $products = Product::all(); $userProducts = User_Product::all(); foreach ($userProducts as $up) { $userPrice = UserPrice::where('product_id', $up->products_id)->first(); $user = User::where('id', '=', $userPrice->user_id)->first(); $product = Product::where('id', '=', $up->products_id)->first(); $targetPrice = $userPrice->target_price; $checkUrl = new CheckUrl(); $provider = $checkUrl->checkurl($product->url); $priceFinder = new PriceFinder(); $productInfo = $priceFinder->{$provider}($product->url); if ($productInfo['price'] <= $targetPrice) { $data = array('price' => 'The price is now lower check it please' . ' ' . 'The link of this product is' . ' ' . $product->url); if ($user) { $subject = 'Track Your Price'; Mail::send('mail.price-notification', $data, function ($message) use($subject, $user) { $message->to($user->email, $user->name)->subject($subject); }); } } } }
public function getTargetPrice($id) { $targetPrice = UserPrice::select('users_price.*')->where('product_id', $id)->first(); return $targetPrice->target_price; }
public function deleteYourProducts($id) { $deleteProductPrice = UserPrice::where('product_id', $id)->delete(); $deletePriceHistory = Price_History::where('products_id', $id)->delete(); $deleteUserProduct = User_Product::where('products_id', $id)->delete(); $deleteProduct = Product::find($id)->delete(); Session::flash('delete-product', 'Product Deleted Successfully..!!'); return Redirect::route('update-your-products'); }