added api for dashboards
This commit is contained in:
		
							
								
								
									
										43
									
								
								app/Transformers/Common/Dashboard.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								app/Transformers/Common/Dashboard.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Transformers\Common; | ||||
|  | ||||
| use App\Models\Common\Dashboard as Model; | ||||
| use League\Fractal\TransformerAbstract; | ||||
|  | ||||
| class Dashboard extends TransformerAbstract | ||||
| { | ||||
|     /** | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $defaultIncludes = ['widgets']; | ||||
|  | ||||
|     /** | ||||
|      * @param  Model $model | ||||
|      * @return array | ||||
|      */ | ||||
|     public function transform(Model $model) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $model->id, | ||||
|             'company_id' => $model->company_id, | ||||
|             'name' => $model->name, | ||||
|             'enabled' => $model->enabled, | ||||
|             'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '', | ||||
|             'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '', | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param  Model $model | ||||
|      * @return mixed | ||||
|      */ | ||||
|     public function includeWidgets(Model $model) | ||||
|     { | ||||
|         if (!$model->widgets) { | ||||
|             return $this->null(); | ||||
|         } | ||||
|  | ||||
|         return $this->collection($model->widgets, new Widget()); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										36
									
								
								app/Transformers/Common/Widget.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								app/Transformers/Common/Widget.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Transformers\Common; | ||||
|  | ||||
| use App\Models\Common\Widget as Model; | ||||
| use League\Fractal\TransformerAbstract; | ||||
|  | ||||
| class Widget extends TransformerAbstract | ||||
| { | ||||
|     /** | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $defaultIncludes = []; | ||||
|  | ||||
|     /** | ||||
|      * @param  Model $model | ||||
|      * @return array | ||||
|      */ | ||||
|     public function transform(Model $model) | ||||
|     { | ||||
|         session(['dashboard_id' => $model->dashboard_id]); | ||||
|  | ||||
|         return [ | ||||
|             'id' => $model->id, | ||||
|             'company_id' => $model->company_id, | ||||
|             'dashboard_id' => $model->dashboard_id, | ||||
|             'class' => $model->class, | ||||
|             'name' => $model->name, | ||||
|             'sort' => $model->sort, | ||||
|             'settings' => $model->settings, | ||||
|             'data' => show_widget($model->class), | ||||
|             'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '', | ||||
|             'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '', | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user