UserResource.php 925 B

12345678910111213141516171819202122232425262728293031323334
  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. 'language' => $this->language,
  21. 'type' => $this->type,
  22. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i'),
  23. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i'),
  24. ];
  25. }
  26. public static function collection($resource): AnonymousResourceCollection
  27. {
  28. return parent::collection($resource);
  29. }
  30. }