@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * Joins the templates table |
| 67 | 67 | * |
| 68 | - * @return \Illuminate\Database\Eloquent\Relations\hasOne |
|
| 68 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 69 | 69 | */ |
| 70 | 70 | public function template() |
| 71 | 71 | { |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | /** |
| 76 | 76 | * Joins the seo table |
| 77 | 77 | * |
| 78 | - * @return \Illuminate\Database\Eloquent\Relations\hasOne |
|
| 78 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 79 | 79 | */ |
| 80 | 80 | public function seo() |
| 81 | 81 | { |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | /** |
| 86 | 86 | * Joins the pages table |
| 87 | 87 | * |
| 88 | - * @return \Illuminate\Database\Eloquent\Relations\hasOne |
|
| 88 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 89 | 89 | */ |
| 90 | 90 | public function parent() |
| 91 | 91 | { |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | /** |
| 34 | 34 | * Rules to validate when creating a model |
| 35 | 35 | * |
| 36 | - * @var array |
|
| 36 | + * @var array |
|
| 37 | 37 | */ |
| 38 | 38 | protected static $createRules = [ |
| 39 | 39 | 'parent_id' => 'integer', |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | /** |
| 49 | 49 | * Indicates if the model should be attributed with created_by and updated_by |
| 50 | 50 | * |
| 51 | - * @var bool |
|
| 51 | + * @var bool |
|
| 52 | 52 | */ |
| 53 | 53 | public $attirbution = true; |
| 54 | 54 | |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
| 59 | 59 | */ |
| 60 | 60 | public function detail() |
| 61 | - { |
|
| 62 | - return $this->hasMany(PageDetail::class, 'page_id', 'id'); |
|
| 63 | - } |
|
| 61 | + { |
|
| 62 | + return $this->hasMany(PageDetail::class, 'page_id', 'id'); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * Joins the templates table |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | * @return \Illuminate\Database\Eloquent\Relations\hasOne |
| 69 | 69 | */ |
| 70 | 70 | public function template() |
| 71 | - { |
|
| 72 | - return $this->hasMany(Template::class, 'id', 'template_id'); |
|
| 73 | - } |
|
| 71 | + { |
|
| 72 | + return $this->hasMany(Template::class, 'id', 'template_id'); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * Joins the seo table |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * @return \Illuminate\Database\Eloquent\Relations\hasOne |
| 79 | 79 | */ |
| 80 | 80 | public function seo() |
| 81 | - { |
|
| 82 | - return $this->hasMany(Seo::class, 'id', 'seo_id'); |
|
| 83 | - } |
|
| 81 | + { |
|
| 82 | + return $this->hasMany(Seo::class, 'id', 'seo_id'); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | 86 | * Joins the pages table |
@@ -88,64 +88,64 @@ discard block |
||
| 88 | 88 | * @return \Illuminate\Database\Eloquent\Relations\hasOne |
| 89 | 89 | */ |
| 90 | 90 | public function parent() |
| 91 | - { |
|
| 92 | - return $this->hasMany(Page::class, 'id', 'parent_id'); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Returns a page and associated detail and template data |
|
| 97 | - * |
|
| 98 | - * @param string $slug |
|
| 99 | - * @return array |
|
| 100 | - */ |
|
| 101 | - public function showBySlug($slug) |
|
| 102 | - { |
|
| 103 | - $data = Page::where(['url' => $slug])->with('template', 'detail.templateDetail')->firstOrFail(); |
|
| 91 | + { |
|
| 92 | + return $this->hasMany(Page::class, 'id', 'parent_id'); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Returns a page and associated detail and template data |
|
| 97 | + * |
|
| 98 | + * @param string $slug |
|
| 99 | + * @return array |
|
| 100 | + */ |
|
| 101 | + public function showBySlug($slug) |
|
| 102 | + { |
|
| 103 | + $data = Page::where(['url' => $slug])->with('template', 'detail.templateDetail')->firstOrFail(); |
|
| 104 | 104 | |
| 105 | - return $this->packagePage($data); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Pacages a Page collection into an array for public consumption |
|
| 110 | - * |
|
| 111 | - * @param Page $data |
|
| 112 | - * @return array |
|
| 113 | - */ |
|
| 114 | - protected function packagePage(Page $data) |
|
| 115 | - { |
|
| 116 | - $seo = $data->seo->first(); |
|
| 117 | - $template = $data->template->first(); |
|
| 105 | + return $this->packagePage($data); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Pacages a Page collection into an array for public consumption |
|
| 110 | + * |
|
| 111 | + * @param Page $data |
|
| 112 | + * @return array |
|
| 113 | + */ |
|
| 114 | + protected function packagePage(Page $data) |
|
| 115 | + { |
|
| 116 | + $seo = $data->seo->first(); |
|
| 117 | + $template = $data->template->first(); |
|
| 118 | 118 | |
| 119 | - $page = [ |
|
| 120 | - 'nav_name' => $data->nav_name, |
|
| 121 | - 'url' => $data->url, |
|
| 122 | - 'title' => $data->title, |
|
| 123 | - 'vars' => [], |
|
| 124 | - 'template' => [ |
|
| 125 | - 'name' => $template->name, |
|
| 126 | - 'class' => $template->class, |
|
| 127 | - 'method' => $template->method, |
|
| 128 | - 'params' => $template->params, |
|
| 129 | - 'template_name' => $template->template_name, |
|
| 130 | - 'layout' => $template->layout, |
|
| 131 | - ], |
|
| 132 | - 'seo' => [ |
|
| 133 | - 'title' => $seo->title, |
|
| 134 | - 'keywords' => $seo->keywords, |
|
| 135 | - 'description' => $seo->description, |
|
| 136 | - 'og_title' => $seo->og_title, |
|
| 137 | - 'og_description' => $seo->og_description, |
|
| 138 | - 'og_image' => $seo->og_image, |
|
| 139 | - 'og_type' => $seo->og_type, |
|
| 140 | - 'fb_app_id' => $seo->fb_app_id, |
|
| 141 | - 'meta' => $seo->meta, |
|
| 142 | - ] |
|
| 143 | - ]; |
|
| 144 | - |
|
| 145 | - foreach ($data->detail as $detail) { |
|
| 146 | - $page['vars'][$detail->templateDetail->first()->var] = $detail->data; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $page; |
|
| 150 | - } |
|
| 119 | + $page = [ |
|
| 120 | + 'nav_name' => $data->nav_name, |
|
| 121 | + 'url' => $data->url, |
|
| 122 | + 'title' => $data->title, |
|
| 123 | + 'vars' => [], |
|
| 124 | + 'template' => [ |
|
| 125 | + 'name' => $template->name, |
|
| 126 | + 'class' => $template->class, |
|
| 127 | + 'method' => $template->method, |
|
| 128 | + 'params' => $template->params, |
|
| 129 | + 'template_name' => $template->template_name, |
|
| 130 | + 'layout' => $template->layout, |
|
| 131 | + ], |
|
| 132 | + 'seo' => [ |
|
| 133 | + 'title' => $seo->title, |
|
| 134 | + 'keywords' => $seo->keywords, |
|
| 135 | + 'description' => $seo->description, |
|
| 136 | + 'og_title' => $seo->og_title, |
|
| 137 | + 'og_description' => $seo->og_description, |
|
| 138 | + 'og_image' => $seo->og_image, |
|
| 139 | + 'og_type' => $seo->og_type, |
|
| 140 | + 'fb_app_id' => $seo->fb_app_id, |
|
| 141 | + 'meta' => $seo->meta, |
|
| 142 | + ] |
|
| 143 | + ]; |
|
| 144 | + |
|
| 145 | + foreach ($data->detail as $detail) { |
|
| 146 | + $page['vars'][$detail->templateDetail->first()->var] = $detail->data; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $page; |
|
| 150 | + } |
|
| 151 | 151 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * Include Page Detail |
| 55 | 55 | * |
| 56 | 56 | * @param \App\LaravelRestCms\Page\Page |
| 57 | - * @return \League\Fractal\ItemResource |
|
| 57 | + * @return \League\Fractal\Resource\Collection |
|
| 58 | 58 | */ |
| 59 | 59 | public function includeDetail(Page $page) |
| 60 | 60 | { |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * Include Template |
| 66 | 66 | * |
| 67 | 67 | * @param \App\LaravelRestCms\Page\Page |
| 68 | - * @return \League\Fractal\ItemResource |
|
| 68 | + * @return \League\Fractal\Resource\Collection |
|
| 69 | 69 | */ |
| 70 | 70 | public function includeTemplate(Page $page) |
| 71 | 71 | { |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * Include Seo |
| 77 | 77 | * |
| 78 | 78 | * @param \App\LaravelRestCms\Page\Page |
| 79 | - * @return \League\Fractal\ItemResource |
|
| 79 | + * @return \League\Fractal\Resource\Collection |
|
| 80 | 80 | */ |
| 81 | 81 | public function includeSeo(Page $page) |
| 82 | 82 | { |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | class PageTransformer extends BaseTransformer { |
| 13 | 13 | |
| 14 | - use HierarchyTransformerTrait; |
|
| 14 | + use HierarchyTransformerTrait; |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * List of resources possible to include |
@@ -21,65 +21,65 @@ discard block |
||
| 21 | 21 | protected $availableIncludes = [ |
| 22 | 22 | 'detail', |
| 23 | 23 | 'template', |
| 24 | - 'seo', |
|
| 24 | + 'seo', |
|
| 25 | 25 | ]; |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Constructor |
|
| 29 | - */ |
|
| 30 | - public function __construct() |
|
| 31 | - { |
|
| 32 | - $this->setupHierarchy(self::class, 'parent'); |
|
| 33 | - } |
|
| 27 | + /** |
|
| 28 | + * Constructor |
|
| 29 | + */ |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 32 | + $this->setupHierarchy(self::class, 'parent'); |
|
| 33 | + } |
|
| 34 | 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 | - } |
|
| 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 | 52 | |
| 53 | - /** |
|
| 54 | - * Include Page Detail |
|
| 55 | - * |
|
| 56 | - * @param \App\LaravelRestCms\Page\Page |
|
| 57 | - * @return \League\Fractal\ItemResource |
|
| 58 | - */ |
|
| 59 | - public function includeDetail(Page $page) |
|
| 60 | - { |
|
| 61 | - return $this->collection($page->detail, new PageDetailTransformer); |
|
| 62 | - } |
|
| 53 | + /** |
|
| 54 | + * Include Page Detail |
|
| 55 | + * |
|
| 56 | + * @param \App\LaravelRestCms\Page\Page |
|
| 57 | + * @return \League\Fractal\ItemResource |
|
| 58 | + */ |
|
| 59 | + public function includeDetail(Page $page) |
|
| 60 | + { |
|
| 61 | + return $this->collection($page->detail, new PageDetailTransformer); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Include Template |
|
| 66 | - * |
|
| 67 | - * @param \App\LaravelRestCms\Page\Page |
|
| 68 | - * @return \League\Fractal\ItemResource |
|
| 69 | - */ |
|
| 70 | - public function includeTemplate(Page $page) |
|
| 71 | - { |
|
| 72 | - return $this->collection($page->template, new TemplateTransformer); |
|
| 73 | - } |
|
| 64 | + /** |
|
| 65 | + * Include Template |
|
| 66 | + * |
|
| 67 | + * @param \App\LaravelRestCms\Page\Page |
|
| 68 | + * @return \League\Fractal\ItemResource |
|
| 69 | + */ |
|
| 70 | + public function includeTemplate(Page $page) |
|
| 71 | + { |
|
| 72 | + return $this->collection($page->template, new TemplateTransformer); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Include Seo |
|
| 77 | - * |
|
| 78 | - * @param \App\LaravelRestCms\Page\Page |
|
| 79 | - * @return \League\Fractal\ItemResource |
|
| 80 | - */ |
|
| 81 | - public function includeSeo(Page $page) |
|
| 82 | - { |
|
| 83 | - return $this->collection($page->seo, new SeoTransformer); |
|
| 84 | - } |
|
| 75 | + /** |
|
| 76 | + * Include Seo |
|
| 77 | + * |
|
| 78 | + * @param \App\LaravelRestCms\Page\Page |
|
| 79 | + * @return \League\Fractal\ItemResource |
|
| 80 | + */ |
|
| 81 | + public function includeSeo(Page $page) |
|
| 82 | + { |
|
| 83 | + return $this->collection($page->seo, new SeoTransformer); |
|
| 84 | + } |
|
| 85 | 85 | } |
| 86 | 86 | \ No newline at end of file |
@@ -15,7 +15,6 @@ |
||
| 15 | 15 | /** |
| 16 | 16 | * Transforms a Page model |
| 17 | 17 | * |
| 18 | - * @param \App\LaravelRestCms\BaseModel $page |
|
| 19 | 18 | * @return array |
| 20 | 19 | */ |
| 21 | 20 | public function transform(BaseModel $seo) |
@@ -12,25 +12,25 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | protected $availableIncludes = []; |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Transforms a Page model |
|
| 17 | - * |
|
| 18 | - * @param \App\LaravelRestCms\BaseModel $page |
|
| 19 | - * @return array |
|
| 20 | - */ |
|
| 21 | - public function transform(BaseModel $seo) |
|
| 22 | - { |
|
| 23 | - return [ |
|
| 24 | - 'id' => (int) $seo->id, |
|
| 25 | - 'title' => $seo->title, |
|
| 26 | - 'keywords' => $seo->keywords, |
|
| 27 | - 'description' => $seo->description, |
|
| 28 | - 'og_title' => $seo->og_title, |
|
| 29 | - 'og_description' => $seo->og_description, |
|
| 30 | - 'og_image' => $seo->og_image, |
|
| 31 | - 'og_type' => $seo->og_type, |
|
| 32 | - 'fb_app_id' => $seo->fb_app_id, |
|
| 33 | - 'meta' => $seo->meta, |
|
| 34 | - ]; |
|
| 35 | - } |
|
| 15 | + /** |
|
| 16 | + * Transforms a Page model |
|
| 17 | + * |
|
| 18 | + * @param \App\LaravelRestCms\BaseModel $page |
|
| 19 | + * @return array |
|
| 20 | + */ |
|
| 21 | + public function transform(BaseModel $seo) |
|
| 22 | + { |
|
| 23 | + return [ |
|
| 24 | + 'id' => (int) $seo->id, |
|
| 25 | + 'title' => $seo->title, |
|
| 26 | + 'keywords' => $seo->keywords, |
|
| 27 | + 'description' => $seo->description, |
|
| 28 | + 'og_title' => $seo->og_title, |
|
| 29 | + 'og_description' => $seo->og_description, |
|
| 30 | + 'og_image' => $seo->og_image, |
|
| 31 | + 'og_type' => $seo->og_type, |
|
| 32 | + 'fb_app_id' => $seo->fb_app_id, |
|
| 33 | + 'meta' => $seo->meta, |
|
| 34 | + ]; |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | /** |
| 31 | 31 | * Rules to validate when creating a model |
| 32 | 32 | * |
| 33 | - * @var array |
|
| 33 | + * @var array |
|
| 34 | 34 | */ |
| 35 | 35 | protected static $createRules = [ |
| 36 | 36 | 'first_name' => 'required', |
@@ -39,41 +39,41 @@ |
||
| 39 | 39 | ], |
| 40 | 40 | ]; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Returns a page and associated detail and template data |
|
| 44 | - * |
|
| 45 | - * @param string $slug |
|
| 46 | - * @return \Illuminate\Http\JsonResponse |
|
| 47 | - */ |
|
| 48 | - public function showBySlug($slug) |
|
| 49 | - { |
|
| 50 | - try { |
|
| 51 | - return \Response::json($this->model->showBySlug($slug)); |
|
| 42 | + /** |
|
| 43 | + * Returns a page and associated detail and template data |
|
| 44 | + * |
|
| 45 | + * @param string $slug |
|
| 46 | + * @return \Illuminate\Http\JsonResponse |
|
| 47 | + */ |
|
| 48 | + public function showBySlug($slug) |
|
| 49 | + { |
|
| 50 | + try { |
|
| 51 | + return \Response::json($this->model->showBySlug($slug)); |
|
| 52 | 52 | |
| 53 | - } catch (\Exception $e) { |
|
| 53 | + } catch (\Exception $e) { |
|
| 54 | 54 | |
| 55 | - return $this->respondNotFound(); |
|
| 56 | - } |
|
| 57 | - } |
|
| 55 | + return $this->respondNotFound(); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Returns a page and associated detail and template data |
|
| 61 | - * |
|
| 62 | - * @param mixed $id |
|
| 63 | - * @return \Illuminate\Http\JsonResponse |
|
| 64 | - */ |
|
| 65 | - public function showWithDetail($id) |
|
| 66 | - { |
|
| 67 | - $this->manager->parseIncludes([ |
|
| 68 | - 'parent', |
|
| 69 | - 'detail', |
|
| 70 | - 'detail.template_detail', |
|
| 71 | - 'template', |
|
| 72 | - 'seo', |
|
| 73 | - //'detail.template_detail.parent', |
|
| 74 | - ]); |
|
| 59 | + /** |
|
| 60 | + * Returns a page and associated detail and template data |
|
| 61 | + * |
|
| 62 | + * @param mixed $id |
|
| 63 | + * @return \Illuminate\Http\JsonResponse |
|
| 64 | + */ |
|
| 65 | + public function showWithDetail($id) |
|
| 66 | + { |
|
| 67 | + $this->manager->parseIncludes([ |
|
| 68 | + 'parent', |
|
| 69 | + 'detail', |
|
| 70 | + 'detail.template_detail', |
|
| 71 | + 'template', |
|
| 72 | + 'seo', |
|
| 73 | + //'detail.template_detail.parent', |
|
| 74 | + ]); |
|
| 75 | 75 | |
| 76 | - return $this->show($id); |
|
| 77 | - } |
|
| 76 | + return $this->show($id); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | 79 | } |
| 80 | 80 | \ No newline at end of file |