AuthResource.php 738 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. class AuthResource 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. 'access_token' => $this['access_token'],
  17. 'token_type' => 'Bearer',
  18. 'expires_in' => 900,
  19. 'user' => new UserResource($this['user']),
  20. ];
  21. }
  22. public static function collection($resource): AnonymousResourceCollection
  23. {
  24. return parent::collection($resource);
  25. }
  26. }