1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/15
- * Time: 17:59
- */
- namespace App\Transformers\Post;
- use App\Models\Post;
- use App\Models\PostLike;
- use League\Fractal\TransformerAbstract;
- class ListTransformer extends TransformerAbstract
- {
- public function __construct($uid, $invite_code)
- {
- $this->uid = $uid;
- $this->invite_code = $invite_code;
- }
- public function transform(Post $post)
- {
- return [
- 'id' => $post['id'],
- 'type' => $post['type'],
- 'uid' => $post['uid'],
- 'username' => subtext($post['username'], 10),
- 'avatar' => $post['avatar'],
- 'title' => $post['title'],
- 'content' => subtext($post['content'], 20),
- 'img' => $post['img'],
- 'praise_count' => $post->data->praise_count,
- 'is_like' => PostLike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0,
- 'h5url' => config('customer.share_post_h5url')."?post_id={$post['id']}&invite_code={$this->invite_code}",
- 'desc_url' => $post['type'] == 'html'?config('customer.app_service_url').'/community/fragment/detail/'.$post['id']:'',
- ];
- }
- }
|