UserInfoResource.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Http\Resources\API;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. use Illuminate\Support\Facades\Auth;
  6. class UserInfoResource extends JsonResource
  7. {
  8. /**
  9. * Transform the resource into an array.
  10. *
  11. * @return array<string, mixed>
  12. */
  13. public function toArray(Request $request): array
  14. {
  15. return [
  16. 'id' => $this->id,
  17. 'name' => $this->name,
  18. 'email' => $this->email,
  19. 'username' => $this->username,
  20. 'phone' => $this->phone,
  21. 'gender' => $this->gender,
  22. 'address' => $this->address,
  23. 'created_at' => (string)$this->created_at,
  24. 'created_by' => new UserProfileResource($this->createdBy),
  25. 'company' => new SimpleCompanyResource($this->company),
  26. 'department' =>new SimpleDepartmentResource($this->department),
  27. 'role' => new RoleResource($this->role),
  28. 'status' =>$this->status,
  29. 'menus' => $this->menus ?: [],
  30. 'super_admin'=>Auth::user()->super_admin,
  31. 'fs_password'=>$this->fs_password,
  32. 'leader' => new UserProfileResource($this->leaderId),
  33. ];
  34. }
  35. }