1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-24 08:44:02 +00:00

Add API StoryTransformer

This commit is contained in:
Daniel Supernault 2019-01-12 13:35:39 -07:00
parent e764b6e8b3
commit fcabd961ce
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -0,0 +1,34 @@
<?php
namespace App\Transformer\Api;
use App\Story;
use League\Fractal;
class StoryTransformer extends Fractal\TransformerAbstract
{
protected $defaultIncludes = [
'items',
];
public function transform(Story $story)
{
return [
'id' => $story->id,
'photo' => $story->profile->avatarUrl(),
'name' => '',
'link' => '',
'lastUpdated' => $story->updated_at->format('U'),
'seen' => $story->seen(),
'items' => [],
];
}
public function includeItems(Story $story)
{
$items = $story->items;
return $this->collection($items, new StoryItemTransformer());
}
}