Beispiel #1
0
 public static function post($token, $promoId, $message)
 {
     if ($token == null or $token == "") {
         throw new \Exception("Session expired, please re-login");
     } else {
         if ($promoId == null or $promoId == "" or Promo::find($promoId) == null) {
             throw new \Exception("Invalid promo item");
         } else {
             if ($message == null or $message == "") {
                 throw new \Exception("Comment must be not empty!");
             }
         }
     }
     $userId = User::query()->where('token', '=', $token)->first()->id;
     if ($userId == null or $userId == "") {
         throw new \Exception("Session expired, please re-login");
     }
     $comment = new Comment();
     $comment->userId = $userId;
     $comment->promoId = $promoId;
     $comment->date = new \DateTime('now', new \DateTimeZone('Asia/Jakarta'));
     $comment->message = $message;
     $comment->save();
     $savedComment = Comment::find($comment->id);
     $savedComment->user = User::query()->where('id', '=', $savedComment->userId)->first(['id', 'username', 'name']);
     unset($savedComment->userId);
     return $savedComment;
 }
Beispiel #2
0
 public static function fillDescriptionPromo()
 {
     $i = 0;
     foreach (Capsule::table(Promo::TABLE_NAME)->where('fullDescription', '=', '')->limit(3)->get() as $item) {
         $promo = Promo::find($item->id);
         $desc = Scraper::scrapDetailPromoWithId($promo->id);
         $promo->fullDescription = $desc;
         $promo->save();
         if ($desc != '') {
             $i++;
         }
     }
     return "Filled {$i} Promos";
 }