1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/17
- * Time: 16:11
- */
- namespace App\Transformers\Post;
- use App\Models\Post;
- use App\Models\PostCollect;
- use App\Models\PostComment;
- use App\Models\PostDislike;
- use App\Models\PostLike;
- use App\Traits\PostTrait;
- use App\Traits\UserTrait;
- use Carbon\Carbon;
- use League\Fractal\TransformerAbstract;
- class PostTransformer extends TransformerAbstract
- {
- use UserTrait;
- use PostTrait;
- public function __construct()
- {
- }
- public function transform(Post $post)
- {
- $user = $this->userInfo($post['uid']);
- $postInfo = $this->getPostInfo($post['id']);
- return [
- 'id' => $post['id'],
- 'type' => $post['type'],
- 'created_at' => $post['created_at'],
- 'uid' => $post['uid'],
- 'username' => $user['username'],
- 'avatar' => $user['avatar'],
- 'topic' => $this->getTopic($post['topic_ids']),
- 'title' => $post['title'],
- 'content' => $post['content'],
- 'location' => $post['location'],
- 'img' => $post['img'],
- 'imgs' => $postInfo['imgs'],
- 'video' => $post['video'],
- 'pv' => getNumber($postInfo['pv']),
- 'praise_count' => $postInfo['praise_count'],
- 'collect_count' => $postInfo['collect_count'],
- 'comment_count' => $postInfo['comment_count'],
- 'available_bean' => $postInfo['available_bean'],
- 'will_collect_bean' => $postInfo['will_collect_bean'],
- ];
- }
- }
|