12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/10
- * Time: 10:56
- */
- namespace App\Transformers\Post;
- use App\Models\PostComment;
- use Illuminate\Support\Carbon;
- use League\Fractal\TransformerAbstract;
- class CommentTransformer extends TransformerAbstract
- {
- public function transform(PostComment $postComment)
- {
- if($postComment['is_delete']){
- $content = '该评论已被删除';
- }elseif($postComment['reply_username']){
- $content = '回复 @'.subtext($postComment['reply_username'], 6).': '.$postComment['content'];
- }else{
- $content = $postComment['content'];
- }
- return [
- 'id' => $postComment['id'],
- 'post_id' => $postComment['post_id'],
- 'parent_id' => $postComment['parent_id'],
- 'uid' => $postComment['uid'],
- 'username' => $postComment['username'],
- 'avatar' => $postComment['avatar'],
- 'content' => $content,
- 'created_at' => Carbon::parse($postComment['created_at'])->toDateTimeString(),
- 'is_delete' => $postComment['is_delete'],
- ];
- }
- }
|