12345678910111213141516171819202122232425262728293031 |
- <?php
- /**
- * Created by IntelliJ IDEA.
- * User: kelyliang
- * Date: 2024/2/29
- * Time: 上午 11:46
- */
- namespace App\Http\Resources\API;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class DepartmentResource extends JsonResource
- {
- public function toArray(Request $request): array
- {
- return[
- 'id' => $this->id,
- 'name' => $this->name,
- 'parent_id' => $this->parent_id,
- 'manager_id' => $this->manager_id,
- 'children' => $this->when($this->children->isNotEmpty(),function (){
- return $this->children->map(function ($child){
- return new DepartmentResource($child);
- })->all();
- }),
- 'created_at' => (string)$this->created_at,
- ];
- }
- }
|