@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | /** |
| 65 | 65 | * Joins the templates table |
| 66 | 66 | * |
| 67 | - * @return \Illuminate\Database\Eloquent\Relations\hasOne |
|
| 67 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 68 | 68 | */ |
| 69 | 69 | public function template() |
| 70 | 70 | { |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | /** |
| 75 | 75 | * Joins the pages table |
| 76 | 76 | * |
| 77 | - * @return \Illuminate\Database\Eloquent\Relations\hasOne |
|
| 77 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
| 78 | 78 | */ |
| 79 | 79 | public function parent() |
| 80 | 80 | { |
@@ -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,52 +77,52 @@ 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 | - /** |
|
| 85 | - * Returns a page and associated detail and template data |
|
| 86 | - * |
|
| 87 | - * @param string $slug |
|
| 88 | - * @return array |
|
| 89 | - */ |
|
| 90 | - public function showBySlug($slug) |
|
| 91 | - { |
|
| 92 | - $data = Page::where(['url' => $slug])->with('template', 'detail.templateDetail')->firstOrFail(); |
|
| 84 | + /** |
|
| 85 | + * Returns a page and associated detail and template data |
|
| 86 | + * |
|
| 87 | + * @param string $slug |
|
| 88 | + * @return array |
|
| 89 | + */ |
|
| 90 | + public function showBySlug($slug) |
|
| 91 | + { |
|
| 92 | + $data = Page::where(['url' => $slug])->with('template', 'detail.templateDetail')->firstOrFail(); |
|
| 93 | 93 | |
| 94 | - return $this->packagePage($data); |
|
| 95 | - } |
|
| 94 | + return $this->packagePage($data); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Pacages a Page collection into an array for public consumption |
|
| 99 | - * |
|
| 100 | - * @param Page $data |
|
| 101 | - * @return array |
|
| 102 | - */ |
|
| 103 | - protected function packagePage(Page $data) |
|
| 104 | - { |
|
| 105 | - $template = $data->template->first(); |
|
| 97 | + /** |
|
| 98 | + * Pacages a Page collection into an array for public consumption |
|
| 99 | + * |
|
| 100 | + * @param Page $data |
|
| 101 | + * @return array |
|
| 102 | + */ |
|
| 103 | + protected function packagePage(Page $data) |
|
| 104 | + { |
|
| 105 | + $template = $data->template->first(); |
|
| 106 | 106 | |
| 107 | - $page = [ |
|
| 108 | - 'nav_name' => $data->nav_name, |
|
| 109 | - 'url' => $data->url, |
|
| 110 | - 'title' => $data->title, |
|
| 111 | - 'vars' => [], |
|
| 112 | - 'template' => [ |
|
| 113 | - 'name' => $template->name, |
|
| 114 | - 'class' => $template->class, |
|
| 115 | - 'method' => $template->method, |
|
| 116 | - 'params' => $template->params, |
|
| 117 | - 'template_name' => $template->template_name, |
|
| 118 | - 'layout' => $template->layout, |
|
| 119 | - ] |
|
| 120 | - ]; |
|
| 107 | + $page = [ |
|
| 108 | + 'nav_name' => $data->nav_name, |
|
| 109 | + 'url' => $data->url, |
|
| 110 | + 'title' => $data->title, |
|
| 111 | + 'vars' => [], |
|
| 112 | + 'template' => [ |
|
| 113 | + 'name' => $template->name, |
|
| 114 | + 'class' => $template->class, |
|
| 115 | + 'method' => $template->method, |
|
| 116 | + 'params' => $template->params, |
|
| 117 | + 'template_name' => $template->template_name, |
|
| 118 | + 'layout' => $template->layout, |
|
| 119 | + ] |
|
| 120 | + ]; |
|
| 121 | 121 | |
| 122 | - foreach ($data->detail as $detail) { |
|
| 123 | - $page['vars'][$detail->templateDetail->first()->var] = $detail->data; |
|
| 124 | - } |
|
| 122 | + foreach ($data->detail as $detail) { |
|
| 123 | + $page['vars'][$detail->templateDetail->first()->var] = $detail->data; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - return $page; |
|
| 127 | - } |
|
| 126 | + return $page; |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -17,7 +17,6 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * Transforms a Page model |
| 19 | 19 | * |
| 20 | - * @param \App\LaravelRestCms\BaseModel $page |
|
| 21 | 20 | * @return array |
| 22 | 21 | */ |
| 23 | 22 | public function transform(BaseModel $template) |
@@ -37,7 +36,7 @@ discard block |
||
| 37 | 36 | * Include Template Detail |
| 38 | 37 | * |
| 39 | 38 | * @param \App\LaravelRestCms\Template\Template $template |
| 40 | - * @return \League\Fractal\ItemResource |
|
| 39 | + * @return \League\Fractal\Resource\Collection |
|
| 41 | 40 | */ |
| 42 | 41 | public function includeDetail(Template $template) |
| 43 | 42 | { |
@@ -14,33 +14,33 @@ |
||
| 14 | 14 | 'detail', |
| 15 | 15 | ]; |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Transforms a Page model |
|
| 19 | - * |
|
| 20 | - * @param \App\LaravelRestCms\BaseModel $page |
|
| 21 | - * @return array |
|
| 22 | - */ |
|
| 23 | - public function transform(BaseModel $template) |
|
| 24 | - { |
|
| 25 | - return [ |
|
| 26 | - 'id' => (int) $template->id, |
|
| 27 | - 'name' => $template->name, |
|
| 28 | - 'class' => $template->class, |
|
| 29 | - 'method' => $template->method, |
|
| 30 | - 'params' => $template->params, |
|
| 31 | - 'template_name' => $template->template_name, |
|
| 32 | - 'layout' => $template->layout, |
|
| 33 | - ]; |
|
| 34 | - } |
|
| 17 | + /** |
|
| 18 | + * Transforms a Page model |
|
| 19 | + * |
|
| 20 | + * @param \App\LaravelRestCms\BaseModel $page |
|
| 21 | + * @return array |
|
| 22 | + */ |
|
| 23 | + public function transform(BaseModel $template) |
|
| 24 | + { |
|
| 25 | + return [ |
|
| 26 | + 'id' => (int) $template->id, |
|
| 27 | + 'name' => $template->name, |
|
| 28 | + 'class' => $template->class, |
|
| 29 | + 'method' => $template->method, |
|
| 30 | + 'params' => $template->params, |
|
| 31 | + 'template_name' => $template->template_name, |
|
| 32 | + 'layout' => $template->layout, |
|
| 33 | + ]; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Include Template Detail |
|
| 38 | - * |
|
| 39 | - * @param \App\LaravelRestCms\Template\Template $template |
|
| 40 | - * @return \League\Fractal\ItemResource |
|
| 41 | - */ |
|
| 42 | - public function includeDetail(Template $template) |
|
| 43 | - { |
|
| 44 | - return $this->collection($template->detail, new TemplateDetailTransformer); |
|
| 45 | - } |
|
| 36 | + /** |
|
| 37 | + * Include Template Detail |
|
| 38 | + * |
|
| 39 | + * @param \App\LaravelRestCms\Template\Template $template |
|
| 40 | + * @return \League\Fractal\ItemResource |
|
| 41 | + */ |
|
| 42 | + public function includeDetail(Template $template) |
|
| 43 | + { |
|
| 44 | + return $this->collection($template->detail, new TemplateDetailTransformer); |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -39,40 +39,40 @@ |
||
| 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 | - //'detail.template_detail.parent', |
|
| 73 | - ]); |
|
| 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 | + //'detail.template_detail.parent', |
|
| 73 | + ]); |
|
| 74 | 74 | |
| 75 | - return $this->show($id); |
|
| 76 | - } |
|
| 75 | + return $this->show($id); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | } |
| 79 | 79 | \ No newline at end of file |