示例#1
0
 /**
  * Gets the last reply for the current forum post.
  *
  * @return array
  */
 public function lastReply()
 {
     try {
         $replies = ForumReply::where('post_id', $this->id)->get();
         if ($replies->isEmpty()) {
             return null;
         }
         $reply = $replies->last();
         return ['author' => $reply->author->name, 'date' => $reply->created_at];
     } catch (Exception $e) {
         return null;
     }
 }
示例#2
0
 /**
  * Get a users post count (posts created and replies).
  * @param int $user_id User Id.
  * @return int
  */
 public function getPostCount($user_id)
 {
     /* Get count from forum posts */
     try {
         $posts = ForumPost::where('author_id', $user_id)->get();
         $posts = count($posts);
     } catch (Exception $e) {
         $posts = 0;
     }
     /* Get count from forum replies */
     try {
         $replies = ForumReply::where('author_id', $user_id)->get();
         $replies = count($replies);
     } catch (Exception $e) {
         $replies = 0;
     }
     /* Return total */
     return $posts + $replies;
 }