/** * 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); }); } } } }