/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $instagram = new InstagramAPI();
     foreach (\App\Supplier::all() as $supplier) {
         $instagram->setAccessToken($supplier->instagramAccount->access_token);
         foreach ($supplier->products()->where('is_active', true)->get() as $product) {
             $comments = $instagram->getMediaComments($product->instagram->id);
             if ($comments->meta->code == 200) {
                 $lastScannedComment = null;
                 for ($i = count($comments->data) - 1; $i >= 0; $i--) {
                     $comment = $comments->data[$i];
                     if ($lastScannedComment == null) {
                         $lastScannedComment = $comment->id;
                     }
                     if ($product->instagram->last_scanned_comment >= $comment->id) {
                         break;
                     }
                     if (strpos(mb_strtolower($comment->text, 'UTF-8'), 'sepete at') !== false) {
                         if ($customer = \App\InstagramAccount::where('instagram_id', $comment->from->id)->first()) {
                             if ($customer->isCustomer()) {
                                 $customer = $customer->instagramable;
                                 \App\WishedProduct::create(['customer_id' => $customer->id, 'product_id' => $product->id, 'count' => 1]);
                             }
                         }
                     }
                 }
                 if ($lastScannedComment != null) {
                     $productInstagram = $product->instagram;
                     $productInstagram->last_scanned_comment = $lastScannedComment;
                     $productInstagram->update();
                 }
             }
         }
     }
 }
 public function addToCart(Request $request, $id)
 {
     if ($product = Product::where(['id' => $id, 'is_active' => true])->first()) {
         $user = Auth::user();
         $quantity = 1;
         if ($request->has('quantity')) {
             if ($request->input('quantity') > 1) {
                 $quantity = $request->input('quantity');
             }
         }
         if ($productInWished = WishedProduct::where(['product_id' => $id, 'customer_id' => $user->id])->first()) {
             $productInWished->count += $quantity;
             $productInWished->update();
         } else {
             WishedProduct::create(['product_id' => $id, 'customer_id' => $user->id, 'count' => $quantity]);
         }
         return redirect()->back()->with(['success' => ['Ürün sepetinize eklendi']]);
     } else {
         return redirect()->back()->withErrors(['messages' => ['Ürün bulunamadı.']]);
     }
 }