First complete upload CasaDoc
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CountryResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
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' => (boolean) $this->eea,
|
||||
'calling_code' => (int) $this->calling_code,
|
||||
'flag' => $this->flag ? url("flags/{$this->flag}") : null
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PermissionResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => (int) $this->id,
|
||||
'name' => $this->name,
|
||||
'display_name' => $this->display_name,
|
||||
'description' => $this->description,
|
||||
'removable' => (boolean) $this->removable,
|
||||
'updated_at' => (string) $this->updated_at,
|
||||
'created_at' => (string) $this->created_at
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Spatie\QueryBuilder\AllowedInclude;
|
||||
|
||||
class RoleResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => (int) $this->id,
|
||||
'name' => $this->name,
|
||||
'display_name' => $this->display_name,
|
||||
'description' => $this->description,
|
||||
'removable' => (boolean) $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()
|
||||
{
|
||||
return [
|
||||
'permissions',
|
||||
AllowedInclude::count('users_count')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SessionResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
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
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
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,
|
||||
'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(\Illuminate\Http\Request $request)
|
||||
{
|
||||
return $this->resource->relationLoaded('role')
|
||||
&& $request->user()->hasPermission('roles.manage');
|
||||
}
|
||||
|
||||
public static function allowedIncludes()
|
||||
{
|
||||
return ['role', 'country'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user