laravel-learn-bbs/app/Transformers/UserTransformer.php

27 lines
993 B
PHP
Raw Normal View History

2018-06-10 08:39:32 +00:00
<?php
namespace App\TransFormers;
use App\Models\User;
use Carbon\Carbon;
use League\Fractal\TransformerAbstract;
class UserTransformer extends TransformerAbstract
{
public function transform(User $user)
{
return [
'id' => $user->id,
'name' => $user->name,
'email' => $user->email,
'avatar' => $user->avatar,
'introduction' => $user->introduction,
'bound_phone' => $user->phone ? true : false,
'bound_wechat' => ($user->weixin_unionid || $user->weixin_openid) ? true : false,
'last_actived_at' => $user->last_actived_at instanceof Carbon ? $user->last_actived_at->toDateTimeString() : $user->last_actived_at,
'created_at' => $user->created_at instanceof Carbon ? $user->created_at->toDateTimeString() : $user->created_at,
'updated_at' => $user->updated_at instanceof Carbon ? $user->updated_at->toDateTimeString() : $user->updated_at,
];
}
}