@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | /** |
| 33 | 33 | * Rules to validate when creating a model |
| 34 | 34 | * |
| 35 | - * @var array |
|
| 35 | + * @var array |
|
| 36 | 36 | */ |
| 37 | 37 | protected static $createRules = [ |
| 38 | 38 | 'parent_id' => 'integer', |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * Indicates if the model should be attributed with created_by and updated_by |
| 49 | 49 | * |
| 50 | - * @var bool |
|
| 50 | + * @var bool |
|
| 51 | 51 | */ |
| 52 | 52 | public $attirbution = true; |
| 53 | 53 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
| 58 | 58 | */ |
| 59 | 59 | public function detail() |
| 60 | - { |
|
| 61 | - return $this->hasMany(PageDetail::class, 'page_id', 'id'); |
|
| 62 | - } |
|
| 60 | + { |
|
| 61 | + return $this->hasMany(PageDetail::class, 'page_id', 'id'); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * Joins the templates table |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | * @return \Illuminate\Database\Eloquent\Relations\hasOne |
| 68 | 68 | */ |
| 69 | 69 | public function template() |
| 70 | - { |
|
| 71 | - return $this->hasMany(Template::class, 'id', 'template_id'); |
|
| 72 | - } |
|
| 70 | + { |
|
| 71 | + return $this->hasMany(Template::class, 'id', 'template_id'); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * Joins the pages table |
@@ -77,13 +77,13 @@ discard block |
||
| 77 | 77 | * @return \Illuminate\Database\Eloquent\Relations\hasOne |
| 78 | 78 | */ |
| 79 | 79 | public function parent() |
| 80 | - { |
|
| 81 | - return $this->hasMany(Page::class, 'id', 'parent_id'); |
|
| 82 | - } |
|
| 80 | + { |
|
| 81 | + return $this->hasMany(Page::class, 'id', 'parent_id'); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - public static function create(array $attributes = []) |
|
| 85 | - { |
|
| 86 | - return parent::create($attributes); |
|
| 87 | - } |
|
| 84 | + public static function create(array $attributes = []) |
|
| 85 | + { |
|
| 86 | + return parent::create($attributes); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | class PageTransformer extends BaseTransformer { |
| 11 | 11 | |
| 12 | - use HierarchyTransformerTrait; |
|
| 12 | + use HierarchyTransformerTrait; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * List of resources possible to include |
@@ -21,51 +21,51 @@ discard block |
||
| 21 | 21 | 'template', |
| 22 | 22 | ]; |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Constructor |
|
| 26 | - */ |
|
| 27 | - public function __construct() |
|
| 28 | - { |
|
| 29 | - $this->setupHierarchy(self::class, 'parent'); |
|
| 30 | - } |
|
| 24 | + /** |
|
| 25 | + * Constructor |
|
| 26 | + */ |
|
| 27 | + public function __construct() |
|
| 28 | + { |
|
| 29 | + $this->setupHierarchy(self::class, 'parent'); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Transforms a Page model |
|
| 34 | - * |
|
| 35 | - * @param \App\LaravelRestCms\BaseModel $page |
|
| 36 | - * @return array |
|
| 37 | - */ |
|
| 38 | - public function transform(BaseModel $page) |
|
| 39 | - { |
|
| 40 | - return [ |
|
| 41 | - 'id' => (int) $page->id, |
|
| 42 | - 'parent_id' => (int)$page->parent_id, |
|
| 43 | - 'template_id' => (int) $page->template_id, |
|
| 44 | - 'nav_name' => $page->nav_name, |
|
| 45 | - 'url' => $page->url, |
|
| 46 | - 'title' => $page->title, |
|
| 47 | - ]; |
|
| 48 | - } |
|
| 32 | + /** |
|
| 33 | + * Transforms a Page model |
|
| 34 | + * |
|
| 35 | + * @param \App\LaravelRestCms\BaseModel $page |
|
| 36 | + * @return array |
|
| 37 | + */ |
|
| 38 | + public function transform(BaseModel $page) |
|
| 39 | + { |
|
| 40 | + return [ |
|
| 41 | + 'id' => (int) $page->id, |
|
| 42 | + 'parent_id' => (int)$page->parent_id, |
|
| 43 | + 'template_id' => (int) $page->template_id, |
|
| 44 | + 'nav_name' => $page->nav_name, |
|
| 45 | + 'url' => $page->url, |
|
| 46 | + 'title' => $page->title, |
|
| 47 | + ]; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Include Page Detail |
|
| 52 | - * |
|
| 53 | - * @param \App\LaravelRestCms\Page\Page |
|
| 54 | - * @return \League\Fractal\ItemResource |
|
| 55 | - */ |
|
| 56 | - public function includeDetail(Page $page) |
|
| 57 | - { |
|
| 58 | - return $this->collection($page->detail, new PageDetailTransformer); |
|
| 59 | - } |
|
| 50 | + /** |
|
| 51 | + * Include Page Detail |
|
| 52 | + * |
|
| 53 | + * @param \App\LaravelRestCms\Page\Page |
|
| 54 | + * @return \League\Fractal\ItemResource |
|
| 55 | + */ |
|
| 56 | + public function includeDetail(Page $page) |
|
| 57 | + { |
|
| 58 | + return $this->collection($page->detail, new PageDetailTransformer); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Include Template |
|
| 63 | - * |
|
| 64 | - * @param \App\LaravelRestCms\Page\Page |
|
| 65 | - * @return \League\Fractal\ItemResource |
|
| 66 | - */ |
|
| 67 | - public function includeTemplate(Page $page) |
|
| 68 | - { |
|
| 69 | - return $this->collection($page->template, new TemplateTransformer); |
|
| 70 | - } |
|
| 61 | + /** |
|
| 62 | + * Include Template |
|
| 63 | + * |
|
| 64 | + * @param \App\LaravelRestCms\Page\Page |
|
| 65 | + * @return \League\Fractal\ItemResource |
|
| 66 | + */ |
|
| 67 | + public function includeTemplate(Page $page) |
|
| 68 | + { |
|
| 69 | + return $this->collection($page->template, new TemplateTransformer); |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | \ No newline at end of file |
@@ -8,31 +8,31 @@ |
||
| 8 | 8 | |
| 9 | 9 | use HierarchyTransformerTrait; |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Constructor |
|
| 13 | - */ |
|
| 14 | - public function __construct() |
|
| 15 | - { |
|
| 16 | - $this->setupHierarchy(self::class, 'parent'); |
|
| 17 | - } |
|
| 11 | + /** |
|
| 12 | + * Constructor |
|
| 13 | + */ |
|
| 14 | + public function __construct() |
|
| 15 | + { |
|
| 16 | + $this->setupHierarchy(self::class, 'parent'); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Transforms a TemplateDetail model |
|
| 21 | - * |
|
| 22 | - * @param \App\LaravelRestCms\BaseModel $templateDetail |
|
| 23 | - * @return array |
|
| 24 | - */ |
|
| 25 | - public function transform(BaseModel $templateDetail) |
|
| 26 | - { |
|
| 27 | - return [ |
|
| 28 | - 'id' => (int) $templateDetail->id, |
|
| 29 | - 'parent_id' => (int) $templateDetail->parent_id, |
|
| 30 | - 'name' => $templateDetail->name, |
|
| 31 | - 'description' => $templateDetail->description, |
|
| 32 | - 'var' => $templateDetail->var, |
|
| 33 | - 'type' => $templateDetail->type, |
|
| 34 | - 'data' => $templateDetail->data, |
|
| 35 | - 'sort' => (int) $templateDetail->sort, |
|
| 36 | - ]; |
|
| 37 | - } |
|
| 19 | + /** |
|
| 20 | + * Transforms a TemplateDetail model |
|
| 21 | + * |
|
| 22 | + * @param \App\LaravelRestCms\BaseModel $templateDetail |
|
| 23 | + * @return array |
|
| 24 | + */ |
|
| 25 | + public function transform(BaseModel $templateDetail) |
|
| 26 | + { |
|
| 27 | + return [ |
|
| 28 | + 'id' => (int) $templateDetail->id, |
|
| 29 | + 'parent_id' => (int) $templateDetail->parent_id, |
|
| 30 | + 'name' => $templateDetail->name, |
|
| 31 | + 'description' => $templateDetail->description, |
|
| 32 | + 'var' => $templateDetail->var, |
|
| 33 | + 'type' => $templateDetail->type, |
|
| 34 | + 'data' => $templateDetail->data, |
|
| 35 | + 'sort' => (int) $templateDetail->sort, |
|
| 36 | + ]; |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -4,34 +4,34 @@ |
||
| 4 | 4 | |
| 5 | 5 | trait HierarchyTransformerTrait { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * The transformer of the parent (usually itself) |
|
| 9 | - * |
|
| 10 | - * @var string |
|
| 11 | - */ |
|
| 12 | - protected $parentTransformer; |
|
| 7 | + /** |
|
| 8 | + * The transformer of the parent (usually itself) |
|
| 9 | + * |
|
| 10 | + * @var string |
|
| 11 | + */ |
|
| 12 | + protected $parentTransformer; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Sets instance vars and adds includes |
|
| 16 | - * |
|
| 17 | - * @param string $parentTransformer |
|
| 18 | - * @param string $method |
|
| 19 | - */ |
|
| 20 | - protected function setupHierarchy($parentTransformer, $method = 'parent') |
|
| 21 | - { |
|
| 22 | - $this->parentTransformer = $parentTransformer; |
|
| 23 | - parent::addToIncludes($method); |
|
| 24 | - } |
|
| 14 | + /** |
|
| 15 | + * Sets instance vars and adds includes |
|
| 16 | + * |
|
| 17 | + * @param string $parentTransformer |
|
| 18 | + * @param string $method |
|
| 19 | + */ |
|
| 20 | + protected function setupHierarchy($parentTransformer, $method = 'parent') |
|
| 21 | + { |
|
| 22 | + $this->parentTransformer = $parentTransformer; |
|
| 23 | + parent::addToIncludes($method); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Include Parent |
|
| 28 | - * |
|
| 29 | - * @param \App\LaravelRestCms\BaseModel |
|
| 30 | - * @return \League\Fractal\ItemResource |
|
| 31 | - */ |
|
| 32 | - public function includeParent(BaseModel $model) |
|
| 33 | - { |
|
| 34 | - return $this->collection($model->parent, new $this->parentTransformer); |
|
| 35 | - } |
|
| 26 | + /** |
|
| 27 | + * Include Parent |
|
| 28 | + * |
|
| 29 | + * @param \App\LaravelRestCms\BaseModel |
|
| 30 | + * @return \League\Fractal\ItemResource |
|
| 31 | + */ |
|
| 32 | + public function includeParent(BaseModel $model) |
|
| 33 | + { |
|
| 34 | + return $this->collection($model->parent, new $this->parentTransformer); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |
@@ -28,22 +28,22 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | protected $collectionName = 'pages'; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Returns a page and associated detail and template data |
|
| 33 | - * |
|
| 34 | - * @param int $id |
|
| 35 | - * @return \Illuminate\Http\JsonResponse |
|
| 36 | - */ |
|
| 37 | - public function showWithDetail($id) |
|
| 38 | - { |
|
| 39 | - $this->manager->parseIncludes([ |
|
| 40 | - 'parent', |
|
| 41 | - 'detail', |
|
| 42 | - 'detail.template_detail', |
|
| 43 | - //'detail.template_detail.parent', |
|
| 44 | - ]); |
|
| 31 | + /** |
|
| 32 | + * Returns a page and associated detail and template data |
|
| 33 | + * |
|
| 34 | + * @param int $id |
|
| 35 | + * @return \Illuminate\Http\JsonResponse |
|
| 36 | + */ |
|
| 37 | + public function showWithDetail($id) |
|
| 38 | + { |
|
| 39 | + $this->manager->parseIncludes([ |
|
| 40 | + 'parent', |
|
| 41 | + 'detail', |
|
| 42 | + 'detail.template_detail', |
|
| 43 | + //'detail.template_detail.parent', |
|
| 44 | + ]); |
|
| 45 | 45 | |
| 46 | - return $this->show($id); |
|
| 47 | - } |
|
| 46 | + return $this->show($id); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | } |
| 50 | 50 | \ No newline at end of file |