PhotoTransformer.php
875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\Transformers;
use App\Model\Photo;
use PhalconRest\Transformers\ModelTransformer;
class PhotoTransformer extends ModelTransformer
{
/**
* Transforms are automatically handled
* based on your model when you extend ModelTransformer
* and assign the modelClass property
*/
protected $modelClass = Photo::class;
protected $availableIncludes = [
'album'
];
public function includeAlbum($photo)
{
return $this->item($photo->getAlbum(), new AlbumTransformer());
}
/**
* You can always transform manually by using
* the following code (below):
*
public function transform(Photo $photo)
{
return [
'id' => $this->int($photo->id),
'title' => $photo->title,
'albumId' => $this->int($photo->albumId)
];
}
*/
}