|
1
|
|
|
<?php namespace App\LaravelRestCms\Page; |
|
2
|
|
|
|
|
3
|
|
|
use App\LaravelRestCms\BaseModel; |
|
4
|
|
|
use App\LaravelRestCms\BaseTransformer; |
|
5
|
|
|
use App\LaravelRestCms\HierarchyTransformerTrait; |
|
6
|
|
|
use App\LaravelRestCms\Page\Page; |
|
7
|
|
|
use App\LaravelRestCms\Page\PageDetailTransformer; |
|
8
|
|
|
use App\LaravelRestCms\Seo\Seo; |
|
9
|
|
|
use App\LaravelRestCms\Seo\SeoTransformer; |
|
10
|
|
|
use App\LaravelRestCms\Template\TemplateTransformer; |
|
11
|
|
|
|
|
12
|
|
|
class PageTransformer extends BaseTransformer { |
|
13
|
|
|
|
|
14
|
|
|
use HierarchyTransformerTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* List of resources possible to include |
|
18
|
|
|
* |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $availableIncludes = [ |
|
22
|
|
|
'detail', |
|
23
|
|
|
'template', |
|
24
|
|
|
'seo', |
|
25
|
|
|
]; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Constructor |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->setupHierarchy(self::class, 'parent'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Transforms a Page model |
|
37
|
|
|
* |
|
38
|
|
|
* @param \App\LaravelRestCms\BaseModel $page |
|
39
|
|
|
* @return array |
|
40
|
|
|
*/ |
|
41
|
|
|
public function transform(BaseModel $page) |
|
42
|
|
|
{ |
|
43
|
|
|
return [ |
|
44
|
|
|
'id' => (int) $page->id, |
|
|
|
|
|
|
45
|
|
|
'parent_id' => (int)$page->parent_id, |
|
|
|
|
|
|
46
|
|
|
'template_id' => (int) $page->template_id, |
|
|
|
|
|
|
47
|
|
|
'nav_name' => $page->nav_name, |
|
|
|
|
|
|
48
|
|
|
'url' => $page->url, |
|
|
|
|
|
|
49
|
|
|
'title' => $page->title, |
|
|
|
|
|
|
50
|
|
|
]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Include Page Detail |
|
55
|
|
|
* |
|
56
|
|
|
* @param \App\LaravelRestCms\Page\Page |
|
57
|
|
|
* @return \League\Fractal\Resource\Collection |
|
58
|
|
|
*/ |
|
59
|
|
|
public function includeDetail(Page $page) |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->collection($page->detail, new PageDetailTransformer); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Include Template |
|
66
|
|
|
* |
|
67
|
|
|
* @param \App\LaravelRestCms\Page\Page |
|
68
|
|
|
* @return \League\Fractal\Resource\Collection |
|
69
|
|
|
*/ |
|
70
|
|
|
public function includeTemplate(Page $page) |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->collection($page->template, new TemplateTransformer); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Include Seo |
|
77
|
|
|
* |
|
78
|
|
|
* @param \App\LaravelRestCms\Page\Page |
|
79
|
|
|
* @return \League\Fractal\Resource\Collection |
|
80
|
|
|
*/ |
|
81
|
|
|
public function includeSeo(Page $page) |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->collection($page->seo, new SeoTransformer); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
} |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.