TRF Certest first commit

This commit is contained in:
2025-02-26 08:57:46 +01:00
commit 3ce064a108
2524 changed files with 475404 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace Vanguard\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CountryResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => (int) $this->id,
'name' => $this->name,
'full_name' => $this->full_name,
'capital' => $this->capital,
'citizenship' => $this->citizenship,
'country_code' => (int) $this->country_code,
'currency' => $this->currency,
'currency_code' => $this->currency_code,
'currency_sub_unit' => $this->currency_sub_unit,
'currency_symbol' => $this->currency_symbol,
'iso_3166_2' => $this->iso_3166_2,
'iso_3166_3' => $this->iso_3166_3,
'region_code' => (int) $this->region_code,
'sub_region_code' => (int) $this->sub_region_code,
'eea' => (bool) $this->eea,
'calling_code' => (int) $this->calling_code,
'flag' => $this->flag ? url("flags/{$this->flag}") : null,
];
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace Vanguard\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PermissionResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => (int) $this->id,
'name' => $this->name,
'display_name' => $this->display_name,
'description' => $this->description,
'removable' => (bool) $this->removable,
'updated_at' => (string) $this->updated_at,
'created_at' => (string) $this->created_at,
];
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace Vanguard\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Spatie\QueryBuilder\AllowedInclude;
class RoleResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => (int) $this->id,
'name' => $this->name,
'display_name' => $this->display_name,
'description' => $this->description,
'removable' => (bool) $this->removable,
'users_count' => is_null($this->users_count) ? null : (int) $this->users_count,
'updated_at' => (string) $this->updated_at,
'created_at' => (string) $this->created_at,
'permissions' => PermissionResource::collection($this->whenLoaded('permissions')),
];
}
public static function allowedIncludes(): array
{
return [
'permissions',
AllowedInclude::count('users_count'),
];
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace Vanguard\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class SessionResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'user_id' => (int) $this->user_id,
'ip_address' => $this->ip_address,
'user_agent' => $this->user_agent,
'browser' => $this->browser,
'platform' => $this->platform,
'device' => $this->device,
'last_activity' => (string) $this->last_activity,
];
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace Vanguard\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'username' => $this->username,
'email' => $this->email,
'phone' => $this->phone,
'avatar' => $this->resource->present()->avatar,
'address' => $this->address,
'country_id' => $this->country_id ? (int) $this->country_id : null,
'role_id' => (int) $this->role_id,
'status' => $this->status->value,
'birthday' => $this->birthday ? $this->birthday->format('Y-m-d') : null,
'last_login' => (string) $this->last_login,
'two_factor_country_code' => (int) $this->two_factor_country_code,
'two_factor_phone' => (string) $this->two_factor_phone,
'two_factor_options' => json_decode($this->two_factor_options, true),
'email_verified_at' => $this->email_verified_at ? (string) $this->email_verified_at : null,
'created_at' => (string) $this->created_at,
'updated_at' => (string) $this->updated_at,
'country' => new CountryResource($this->whenLoaded('country')),
'role' => $this->when($this->canViewRole($request), function () {
return new RoleResource($this->resource->role);
}),
];
}
private function canViewRole(Request $request): bool
{
return $this->resource->relationLoaded('role')
&& $request->user()->hasPermission('roles.manage');
}
public static function allowedIncludes(): array
{
return ['role', 'country'];
}
}