12345678910111213141516171819202122232425262728293031323334 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/17
- * Time: 18:10
- */
- namespace App\Transformers\Topic;
- 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->follow->count() + $topic['base_count']),
- 'is_follow' => $isFollow,
- ];
- }
- }
|