UserResource.php 880 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Http\Resources;
  3. use Carbon\Carbon;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
  7. class UserResource extends JsonResource
  8. {
  9. /**
  10. * Transform the resource into an array.
  11. *
  12. * @return array<string, mixed>
  13. */
  14. public function toArray(Request $request): array
  15. {
  16. return [
  17. 'id' => $this->id,
  18. 'name' => $this->name,
  19. 'email' => $this->email,
  20. 'phone' => $this->phone,
  21. 'language' => $this->language,
  22. 'type' => $this->type,
  23. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i'),
  24. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i'),
  25. ];
  26. }
  27. public static function collection($resource): AnonymousResourceCollection
  28. {
  29. return parent::collection($resource);
  30. }
  31. }