first init
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Auth\Transformers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'ic_number' => $this->ic_number,
|
||||
'position' => $this->position,
|
||||
'phone_number' => $this->phone_number,
|
||||
'image_url' => $this->image_url ? Storage::disk('public')->url($this->image_url) : null,
|
||||
'status' => $this->status,
|
||||
'two_factor_secret' => $this->two_factor_secret,
|
||||
'two_factor_recovery_codes' => $this->two_factor_recovery_codes,
|
||||
'two_factor_confirmed_at' => $this->two_factor_confirmed_at,
|
||||
'email_verified_at' => $this->email_verified_at,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
'deleted_at' => $this->deleted_at,
|
||||
'roles' => $this->whenLoaded('roles', function () {
|
||||
return $this->roles->map(function ($role) {
|
||||
return [
|
||||
'id' => $role->id,
|
||||
'name' => $role->name,
|
||||
'fullname' => $role->fullname ?? null,
|
||||
'context' => $role->context ?? 'member',
|
||||
'guard_name' => $role->guard_name,
|
||||
'permissions' => $this->when($role->relationLoaded('permissions'), function () use ($role) {
|
||||
return $role->permissions->map(function ($permission) {
|
||||
return [
|
||||
'id' => $permission->id,
|
||||
'name' => $permission->name,
|
||||
'guard_name' => $permission->guard_name,
|
||||
'route_name' => $permission->route_name,
|
||||
'created_at' => $permission->created_at,
|
||||
'updated_at' => $permission->updated_at,
|
||||
];
|
||||
});
|
||||
}),
|
||||
'created_at' => $role->created_at,
|
||||
'updated_at' => $role->updated_at,
|
||||
];
|
||||
});
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user