123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/6
- * Time: 14:08
- */
- namespace App\Transformers\Circle;
- use App\Models\Post;
- use App\Traits\PostTrait;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Facades\Redis;
- use League\Fractal\TransformerAbstract;
- class PostListTransformer extends TransformerAbstract
- {
- use PostTrait;
- public function __construct($circleId)
- {
- $this->circle_id = $circleId;
- }
- public function transform(Post $post)
- {
- $key = 'circle_articles_' . $this->circle_id;
- $isexists = Redis::zscore($key, $post['id']);
- return [
- 'id' => $post['id'],
- 'created_at' => Carbon::parse($post['created_at'])->toDateTimeString(),
- 'uid' => $post['uid'],
- 'username' => $post['username'],
- 'topic' => $this->getTopic($post['topic_ids'], 1),
- 'content' => subtext(strip_tags($post['content']), 20),
- 'image' => $post['img'],
- 'is_exists_circle' => $isexists ? 1 : 0,
- ];
- }
- }
|