You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
884 B

  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Resources\Json\JsonResource;
  4. class UserResource extends JsonResource
  5. {
  6. public function toArray($request)
  7. {
  8. $resource = [
  9. '_service' => 'user',
  10. '_resource' => 'user',
  11. ];
  12. foreach ($this->getAttributes() as $attribute => $value) {
  13. switch ($attribute) {
  14. case 'id':
  15. case 'name':
  16. case 'mobile':
  17. case 'email':
  18. case 'created_at':
  19. case 'updated_at':
  20. $resource[$attribute] = $value;
  21. break;
  22. }
  23. }
  24. $resource['includes']['fingerprints'] = $this->whenLoaded('fingerprints', function () {
  25. return FingerprintResource::collection($this->fingerprints);
  26. });
  27. return $resource;
  28. }
  29. }