Example #1
0
 public static function boot()
 {
     parent::boot();
     static::created(function (Comment $comment) {
         event(new NewComment($comment));
         if ($post = $comment->post) {
             $post->commentCount += 1;
             $post->save();
         }
         if ($comment->parentCommentId && ($parent = $comment->parentComment)) {
             $parent->replyCount += 1;
             $parent->save();
         }
     });
     static::deleted(function (Comment $comment) {
         if ($post = $comment->post) {
             $post->commentCount -= 1;
             $post->save();
         }
         if ($comment->parentCommentId && ($parent = $comment->parentComment)) {
             $parent->replyCount -= 1;
             $parent->save();
         }
     });
 }
Example #2
0
 public function toArray()
 {
     $array = parent::toArray();
     $array['url'] = $this->getUrl();
     $array['thumbUrl'] = $this->getThumbUrl();
     return $array;
 }
Example #3
0
 public static function boot()
 {
     parent::boot();
     static::created(function (Like $like) {
         event(new NewLike($like));
     });
 }
 public function toArray()
 {
     $array = parent::toArray();
     $array['user'] = $this->getUser();
     $array['task'] = $this->getTask();
     return $array;
 }
Example #5
0
 public static function boot()
 {
     parent::boot();
     static::saving(function (Category $category) {
         $category->parentCategoryId = $category->parentCategoryId ? (int) $category->parentCategoryId : null;
     });
 }
 public function toArray()
 {
     $array = parent::toArray();
     $array['text'] = $this->getText();
     $array['icon'] = $this->getIcon();
     $array['destination'] = $this->getDestination();
     $array['image'] = $this->getImage();
     return $array;
 }
Example #7
0
 public static function boot()
 {
     parent::boot();
     static::saving(function (Sticker $sticker) {
         $sticker->requiredTasks = $sticker->requiredTasks ? (int) $sticker->requiredTasks : null;
         Cache::forget('stickerSelectList');
     });
     static::created(function (Sticker $sticker) {
         event(new NewSticker($sticker));
     });
 }
Example #8
0
 public function toArray()
 {
     $array = parent::toArray();
     $array['user'] = $this->getUser();
     $array['image'] = $this->getImage();
     $array['commentsUrl'] = "/posts/{$this->id}/comments";
     if ($user = Auth::user()) {
         /** @var User $user */
         $array['liked'] = $this->getLikeManager()->userLikes($user);
     } else {
         $array['liked'] = null;
     }
     return $array;
 }
Example #9
0
 public function toArray()
 {
     $array = parent::toArray();
     $array['bgUrl'] = $this->getBgUrl();
     /** @var User $user */
     if ($user = Auth::user()) {
         $toDoManager = new ToDoManager();
         $array['isOnToDoList'] = $toDoManager->userHasTaskToDo($this, $user);
         $array['hasCompleted'] = $user->hasCompletedTask($this);
     }
     $array['cost'] = $this->cost ? round($this->cost) : null;
     $array['time'] = $this->time ? round($this->time) : null;
     $array['rating'] = $this->rating ? round($this->rating) : null;
     return $array;
 }
Example #10
0
 /**
  * @return array
  */
 public function toArray()
 {
     $array = parent::toArray();
     if (!Auth::check() || Auth::user()->id !== $this->id) {
         unset($array['email']);
         unset($array['admin']);
         unset($array['updatedAt']);
     }
     if ($image = $this->getImage()) {
         $array['imageUrl'] = $image->getUrl();
         $array['imageThumbUrl'] = $image->thumb ? $image->getThumbUrl() : $image->getUrl();
     } else {
         $array['imageUrl'] = null;
         $array['imageThumbUrl'] = null;
     }
     $array['possessiveName'] = LangHelpers::possessive($this->username);
     return $array;
 }
Example #11
0
 public function toArray()
 {
     $array = parent::toArray();
     $array['user'] = $this->getUser();
     $array['sticker'] = $this->getSticker();
     $array['task'] = $this->getTask();
     $array['post'] = $this->postId ? $this->post : null;
     $array['comment'] = $this->commentId ? $this->comment : null;
     $this->setupForType();
     $array['action'] = $this->action;
     $user = Auth::getUser();
     if ($this->likeManager) {
         $array['likeCount'] = $this->likeManager->getCount();
         if ($user) {
             $array['liked'] = $this->likeManager->userLikes($user);
         }
     }
     return $array;
 }
 public function toArray()
 {
     $array = parent::toArray();
     $array['imageUrl'] = $this->getImageUrl();
     return $array;
 }