Example #1
0
 /**
  *
  * Returns array of post_count random posts
  *
  * @return Collection
  */
 protected function getPosts()
 {
     $count = $this->property('postsCount');
     $posts = Post::orderBy(DB::raw('RAND()'))->take($count)->get();
     foreach ($posts as $post) {
         $post->url = $post->setUrl($this->property('postPage'), $this->controller);
     }
     $this->cachePosts($posts);
     return $posts;
 }
Example #2
0
 /**
  *
  * Returns date (Carbon object) set to the date of the very first post
  * or to current date if there are no posts
  *
  * @return Carbon
  */
 protected static function getFirstDate()
 {
     $post = BlogPost::orderBy('published_at', 'asc')->isPublished()->first();
     if (!$post) {
         $date = new Carbon();
     } else {
         $date = new Carbon($post->published_at);
     }
     $date->setTime(0, 0);
     return $date;
 }