/**
  * Update Post Metadata
  *
  * @param Post $post
  */
 public function updateMetadata(Post $post)
 {
     $metadata = json_decode(json_encode($post->metadata), true);
     $post->metadata = $this->applyRules($metadata);
     $post->save();
     $this->info(sprintf('Post ID %s : UPDATED', $post->id));
 }
Exemplo n.º 2
0
 /**
  * get post by tag/tags
  *
  * @param      $tags string|array
  *
  * @param bool $paginate
  *
  * @return mixed
  */
 public function getByTags($tags, $paginate = false)
 {
     $query = $this->post->whereHas('tags', function ($q) use($tags) {
         if (is_string($tags)) {
             $q->where('title', $tags);
         } else {
             $q->whereIn('id', $tags);
         }
     });
     $query->orderBy('updated_at', 'DESC');
     $query->published();
     if ($paginate) {
         return $query->paginate();
     }
     return $query->get();
 }
Exemplo n.º 3
0
 /**
  * @param  Post $post
  * @param bool  $withCategoryTitle
  *
  * @return array
  *
  */
 public function buildPost(Post $post, $withCategoryTitle = false)
 {
     $post->load('categories');
     $postArray['id'] = $post->id;
     $postArray = array_merge($postArray, (array) $post->apiMetadata);
     $postArray['like_count'] = $post->likes;
     $postArray['view_count'] = (int) $post->view_count;
     $postArray['share_count'] = (int) $post->share_count;
     $postArray['tags'] = $post->tags->lists('title')->toArray();
     if ($withCategoryTitle) {
         $postArray['categories'] = $post->categories->lists('title')->toArray();
     } else {
         $postArray['section_category'] = $post->categories->lists('id')->toArray();
     }
     $postArray['created_at'] = $post->created_at->timestamp;
     $postArray['updated_at'] = $post->updated_at->timestamp;
     return $postArray;
 }
Exemplo n.º 4
0
 /**
  * post detail
  *
  * @param $id
  *
  * @return array
  */
 public function find($id)
 {
     $post = $this->postModel->find($id);
     return $this->formatPost($post);
 }