|
@@ -5,8 +5,10 @@
|
|
|
* Date: 2019/6/17
|
|
|
* Time: 18:10
|
|
|
*/
|
|
|
-namespace App\Transformers\Topic;
|
|
|
|
|
|
+namespace App\Transformers\Topic;
|
|
|
+
|
|
|
+use App\Models\InterestCircle;
|
|
|
use App\Models\Topic;
|
|
|
use Carbon\Carbon;
|
|
|
use League\Fractal\TransformerAbstract;
|
|
@@ -17,18 +19,33 @@ class TopicDetailTransformer extends TransformerAbstract
|
|
|
{
|
|
|
$this->uid = $uid;
|
|
|
}
|
|
|
+
|
|
|
public function transform(Topic $topic)
|
|
|
{
|
|
|
$isFollow = 0;
|
|
|
- if($this->uid){
|
|
|
- $isFollow = $topic->follow->where('uid', $this->uid)->count()?1: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;
|
|
|
+ }
|
|
|
}
|