1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Repositories\Transformers\CMS;
- use App\Repositories\Enums\CMS\SettingTypeEnum;
- use App\Repositories\Models\Base\Resource;
- use Carbon\Carbon;
- use League\Fractal\TransformerAbstract;
- use App\Repositories\Models\CMS\Setting;
- /**
- * Class SettingTransformer.
- *
- * @package namespace App\Repositories\Transformers\CMS;
- */
- class SettingTransformer extends TransformerAbstract
- {
- /**
- * Transform the Setting entity.
- *
- * @param \App\Repositories\Models\CMS\Setting $model
- *
- * @return array
- */
- public function transform(Setting $model)
- {
- switch ((int)$model->type) {
- case SettingTypeEnum::STARING:
- case SettingTypeEnum::TEXT:
- $body = $model->body;
- break;
- case SettingTypeEnum::IMG:
- $body = Resource::query()->where('id', $model->body)->select(['id', 'path', 'url'])->first();
- break;
- }
- return [
- 'id' => (int)$model->id,
- 'name' => $model->name,
- 'key' => $model->key,
- 'type' => $model->type,
- 'type_name' => SettingTypeEnum::getDescription($model->type),
- 'body' => $body,
- 'is_init' => $model->is_init,
- 'sort' => $model->sort,
- 'status' => $model->status,
- 'created_at' => $model->created_at->format(Carbon::DEFAULT_TO_STRING_FORMAT),
- 'updated_at' => $model->updated_at->format(Carbon::DEFAULT_TO_STRING_FORMAT)
- ];
- }
- }
|