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

29 lines
739 B
PHP
Raw Permalink Normal View History

2018-06-10 09:25:41 +00:00
<?php
/**
* Created by PhpStorm.
* User: xing
* Date: 2018/6/10
* Time: 16:47
*/
namespace App\Transformers;
use App\Models\Image;
use Carbon\Carbon;
use League\Fractal\TransformerAbstract;
class ImageTransformer extends TransformerAbstract
{
public function transform(Image $image)
{
return [
'id' => $image->id,
'user_id' => $image->user_id,
'type' => $image->type,
'path' => $image->path,
'created_at' => $image->created_at instanceof Carbon ? $image->created_at->toDateTimeString() : $image->created_at,
'updated_at' => $image->updated_at instanceof Carbon ? $image->updated_at->toDateTimeString() : $image->updated_at,
];
}
}