/** * 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 deactivateAccount() { $userProduct = User_Product::select('products_id')->join('products', 'products.id', '=', 'user_product.products_id')->where('user_product.user_id', Auth::user()->id)->get()->count(); if ($userProduct > 0) { $message = 'If You Want to deactivate Your Account Please Delete All Products First...!!'; return Redirect::route('user-profile')->withErrors($message); } else { $user = User::where('id', Auth::user()->id)->delete(); $userProfile = UserProfile::where('user_id', Auth::user()->id)->delete(); return Redirect::route('register'); } }