123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/17
- * Time: 18:10
- */
- namespace App\Transformers\Topic;
- use App\Models\InterestCircle;
- use App\Models\Topic;
- use Carbon\Carbon;
- use League\Fractal\TransformerAbstract;
- class TopicDetailTransformer extends TransformerAbstract
- {
- public function __construct($uid)
- {
- $this->uid = $uid;
- }
- public function transform(Topic $topic)
- {
- $isFollow = 0;
- if ($this->uid) {
- $isFollow = $topic->follow->where('uid', $this->uid)->count() ? 1 : 0;
- }
- return [
- 'id' => $topic['id'],
- 'name' => $topic['name'],
- 'img' => $topic['img'],
- 'follow_count' => getNumber($topic['use_count'] + $topic['base_count']),
- 'is_follow' => $isFollow,
- 'circle' => $this->getCircleInfo($topic['circle_id'])
- ];
- }
- public function getCircleInfo($circleId)
- {
- $circleInfo = InterestCircle::find($circleId);
- if ($circleInfo) {
- $circle['id'] = $circleInfo->id;
- $circle['name'] = $circleInfo->name;
- } else {
- $circle = new \stdClass();
- }
- return $circle;
- }
- }
|