12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/10
- * Time: 17:21
- */
- namespace App\Transformers\Post;
- use App\Models\PostLog;
- use Illuminate\Support\Carbon;
- use League\Fractal\TransformerAbstract;
- class LogTransformer extends TransformerAbstract
- {
- public function transform(PostLog $postLog)
- {
- $type = [
- 'add_pv' => '增加浏览量:',
- 'add_praise_count' => '增加点赞数:',
- 'add_collect_count' => '增加收藏数:',
- 'add_share_count' => '增加分享数:',
- 'delete' => '删除内容:',
- 'update_topic' => '编辑内容话题:',
- 'suggest' => '推荐内容:',
- 'cancel_suggest' => '取消推荐内容:',
- ];
- $data = json_decode($postLog['content']);
- $content = '';
- foreach($data as $key => $val){
- if(!$val) continue;
- $content .= $type[$key] . $val .'、';
- }
- $content = rtrim($content, '、');
- return [
- 'id' => $postLog['id'],
- 'username' => $postLog['username'],
- 'log_type' => $postLog['log_type'],
- 'created_at' => Carbon::parse($postLog['created_at'])->toDateTimeString(),
- 'content' => $content,
- ];
- }
- }
|