MenuTransformer.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Repositories\Transformers\Base;
  3. use Carbon\Carbon;
  4. use Illuminate\Support\Facades\App;
  5. use League\Fractal\TransformerAbstract;
  6. use App\Repositories\Models\Base\Menu;
  7. /**
  8. * Class MenuTransformer.
  9. *
  10. * @package namespace App\Repositories\Transformers\Base;
  11. */
  12. class MenuTransformer extends TransformerAbstract
  13. {
  14. /**
  15. * Transform the Menu entity.
  16. *
  17. * @param \App\Repositories\Models\Base\Menu $model
  18. *
  19. * @return array
  20. */
  21. public function transform(Menu $model)
  22. {
  23. return [
  24. 'id' => (int)$model->id,
  25. 'parent_id' => $model->parent_id,
  26. 'parent_name' => $model->parent->name ?? '--',
  27. 'name' => $model->name,
  28. 'zh_title' => $model->zh_title,
  29. 'en_title' => $model->en_title,
  30. 'path' => $model->path,
  31. 'component' => $model->component,
  32. 'redirect' => $model->redirect,
  33. 'meta' => $model->meta,
  34. 'sort' => $model->sort,
  35. 'status' => $model->status,
  36. 'created_at' => $model->created_at->format(Carbon::DEFAULT_TO_STRING_FORMAT),
  37. 'updated_at' => $model->updated_at->format(Carbon::DEFAULT_TO_STRING_FORMAT)
  38. ];
  39. }
  40. }