DepartmentResource.php 568 B

12345678910111213141516171819202122232425
  1. <?php
  2. /**
  3. * Created by IntelliJ IDEA.
  4. * User: kelyliang
  5. * Date: 2024/2/29
  6. * Time: 上午 11:46
  7. */
  8. namespace App\Http\Resources\API;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Http\Resources\Json\JsonResource;
  11. class DepartmentResource extends JsonResource
  12. {
  13. public function toArray(Request $request): array
  14. {
  15. return[
  16. 'id' => $this->id,
  17. 'name' => $this->name,
  18. 'parent_id' => $this->parent_id,
  19. 'children' => $this->parent_id == 0 ? DepartmentResource::collection($this->children) : [],
  20. ];
  21. }
  22. }