VueRouterResource.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Models\VueRouter;
  4. use App\Traits\ModelTree;
  5. use App\Traits\ResourceRolePermissionHelpers;
  6. class VueRouterResource extends JsonResource
  7. {
  8. use ResourceRolePermissionHelpers;
  9. use ModelTree;
  10. public function toArray($request)
  11. {
  12. /** @var VueRouter $model */
  13. $model = $this->resource;
  14. return [
  15. 'id' => $model->id,
  16. 'parent_id' => $model->parent_id,
  17. 'title' => $model->title,
  18. 'icon' => $model->icon,
  19. 'path' => $model->path,
  20. 'order' => $model->order,
  21. 'cache' => $model->cache,
  22. 'menu' => $model->menu,
  23. 'roles' => $this->when(
  24. $this->onlyRolePermissionIds,
  25. $model->roles()->pluck('id'),
  26. AdminRoleResource::collection($this->whenLoaded('roles'))
  27. ),
  28. 'permission' => $model->permission,
  29. 'created_at' => (string) $model->created_at,
  30. 'updated_at' => (string) $model->updated_at,
  31. ];
  32. }
  33. }