AdminRoleResource.php 784 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Models\AdminRole;
  4. use App\Models\VueRouter;
  5. use App\Traits\ModelTree;
  6. use Illuminate\Support\Facades\Log;
  7. class AdminRoleResource extends JsonResource
  8. {
  9. use ModelTree;
  10. public function toArray($request)
  11. {
  12. /** @var AdminRole $model */
  13. $model = $this->resource;
  14. return [
  15. 'id' => $model->id,
  16. 'name' => $model->name,
  17. 'slug' => $model->slug,
  18. 'permissions' => AdminPermissionResource::collection($this->whenLoaded('permissions')),
  19. 'vue_routers' => VueRouterResource::collection($this->whenLoaded('vue_routers')),
  20. 'created_at' => (string) $model->created_at,
  21. 'updated_at' => (string) $model->updated_at,
  22. ];
  23. }
  24. }