Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
gilour
/
back
/
app
/
Responses
:
TokenResponse.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php declare(strict_types=1); namespace App\Responses; use App\BaseClasses\BaseResponse; use Illuminate\Http\{JsonResponse}; class TokenResponse extends BaseResponse { private int $status; private string $message; private string $token; private int $userId; public function __construct( int $status, string $message, string $token, int $userId ) { $this->status = $status; $this->message = $message; $this->token = $token; $this->userId = $userId; } public function toResponse($request): JsonResponse { return new JsonResponse( data: [ 'status' => $this->status, 'data' => [ 'message' => __(key: $this->message), 'token' => __(key: $this->token), 'userId' => __(key: $this->userId), ], 'metadata' => [ 'request_id' => str()->uuid()->toString(), 'timestamp' => now()->toIso8601String() ], ], status: $this->status ); } public static function example(): array { return [ 'data' => [ 'message' => 'Token generated successfully', 'token' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpvaG4iOiIxMjM0NTQ4ODM3ODA2IiwidmFsdWUifQ...', 'userId' => 123, ], 'metadata' => [ 'request_id' => str()->uuid()->toString(), 'timestamp' => now()->toIso8601String() ] ]; } }