1234567891011121314151617181920212223242526 |
- <?php
- namespace App\Transformers\Post;
- use App\Models\Post;
- use App\Traits\PostTrait;
- use Illuminate\Support\Carbon;
- use League\Fractal\TransformerAbstract;
- class PostTopicTransformer extends TransformerAbstract
- {
- use PostTrait;
- public function transform(Post $post)
- {
- return [
- 'id' => $post['id'],
- 'created_at' => Carbon::parse($post['created_at'])->toDateTimeString(),
- 'uid' => $post['uid'],
- 'username' => $post['username'],
- 'avatar' => $post['avatar'],
- 'topic' => $this->getTopic($post['topic_ids'], 1),
- 'img' => $post['img'],
- 'content' => subtext(strip_tags($post['content']), 20),
- ];
- }
- }
|