|
@@ -0,0 +1,56 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * Created by PhpStorm.
|
|
|
+ * User: Administrator
|
|
|
+ * Date: 2019/6/18
|
|
|
+ * Time: 10:08
|
|
|
+ */
|
|
|
+namespace App\Transformers\Post;
|
|
|
+
|
|
|
+use App\Models\Post;
|
|
|
+use App\Models\PostCollect;
|
|
|
+use App\Models\PostLike;
|
|
|
+use App\Traits\UserTrait;
|
|
|
+use League\Fractal\TransformerAbstract;
|
|
|
+
|
|
|
+class VideoTransformer extends TransformerAbstract
|
|
|
+{
|
|
|
+ use UserTrait;
|
|
|
+ public function __construct($uid)
|
|
|
+ {
|
|
|
+ $this->uid = $uid;
|
|
|
+ }
|
|
|
+ public function transform(Post $post)
|
|
|
+ {
|
|
|
+ $isFollow = 0;
|
|
|
+ $followStatus = $this->getFollowStatus($this->uid, $post['uid']);
|
|
|
+ if($followStatus){
|
|
|
+ $isFollow = $followStatus;
|
|
|
+ }
|
|
|
+ $topic = [];
|
|
|
+ foreach($post->topic() as $key => $val){
|
|
|
+ $topic[] = [
|
|
|
+ 'id' => $key,
|
|
|
+ 'name' => $val
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ return [
|
|
|
+ 'id' => $post['id'],
|
|
|
+ 'type' => $post['type'],
|
|
|
+ 'uid' => $post['uid'],
|
|
|
+ 'username' => $post['username'],
|
|
|
+ 'avatar' => $post['avatar'],
|
|
|
+ 'title' => $post['title'],
|
|
|
+ 'content' => $post['content'],
|
|
|
+ 'img' => $post['img'],
|
|
|
+ 'video' => $post['video'],
|
|
|
+ 'topic' => $topic,
|
|
|
+ 'praise_count' => $post->data->praise_count,
|
|
|
+ 'collect_count' => $post->data->collect_count,
|
|
|
+ 'comment_count' => $post->data->comment_count,
|
|
|
+ 'is_like' => PostLike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0,
|
|
|
+ 'is_collect' => PostCollect::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0,
|
|
|
+ 'is_follow' => $isFollow,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+}
|