complete Complete User Request Submission section RAD-1
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use App\Enums\DocumentStatusEnum;
|
||||
use App\Enums\DocumentPriorityEnum;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DocumentEditFormResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'note' => $this->note,
|
||||
'priority' => $this->priority,
|
||||
'image' => $this->image,
|
||||
'code' => $this->code,
|
||||
'modality' => $this->modality,
|
||||
'status' => $this->status instanceof DocumentStatusEnum ? $this->status->name : $this->status,
|
||||
'priority' => $this->priority instanceof DocumentPriorityEnum ? $this->priority->name : $this->priority,
|
||||
'pet_id' => $this->pet_id,
|
||||
'requester' => $this->relationLoaded('requester') ? optional($this->requester)->only(['id','fullname']) : null,
|
||||
'submitted_at' => $this->submitted_at,
|
||||
'processing_deadline' => $this->processing_deadline,
|
||||
'primary_files' => $this->relationLoaded('primaryFiles') ? $this->primaryFiles->map(function ($file) {
|
||||
return [
|
||||
'id' => $file->id,
|
||||
'filename' => $file->filename,
|
||||
'mime_type' => $file->mime_type,
|
||||
];
|
||||
}) : [],
|
||||
'history_files' => $this->relationLoaded('historyFiles') ? $this->historyFiles->map(function ($file) {
|
||||
return [
|
||||
'id' => $file->id,
|
||||
'filename' => $file->filename,
|
||||
'mime_type' => $file->mime_type,
|
||||
];
|
||||
}) : [],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use App\Enums\DocumentStatusEnum;
|
||||
use App\Enums\DocumentPriorityEnum;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DocumentResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'note' => $this->note,
|
||||
'priority' => $this->priority,
|
||||
'image' => $this->image,
|
||||
'code' => $this->code,
|
||||
'modality' => $this->modality,
|
||||
'status' => $this->status,
|
||||
'priority' => $this->priority,
|
||||
'pet' => $this->relationLoaded('pet') ? optional($this->pet)->only(['id','name','birthday']) : null,
|
||||
'requester' => $this->relationLoaded('requester') ? optional($this->requester)->only(['id','fullname']) : null,
|
||||
'submitted_at' => verta($this->submitted_at)->format('%Y/%m/%d - H:i'),
|
||||
'processing_deadline' => verta($this->processing_deadline)->format('%Y/%m/%d - H:i'),
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PermissionResource 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,
|
||||
'label' => $this->label,
|
||||
'created_at' => verta($this->created_at)->format('%d %B %Y %H:%M:%S'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class PetResource extends JsonResource
|
||||
{
|
||||
|
||||
function calculateAge($birthday) {
|
||||
if (!$birthday) return null;
|
||||
|
||||
$birth = Carbon::parse($birthday);
|
||||
$now = Carbon::now();
|
||||
|
||||
$years = (int) $birth->diffInYears($now);
|
||||
$months = (int) $birth->copy()->addYears($years)->diffInMonths($now);
|
||||
$days = (int) $birth->copy()->addYears($years)->addMonths($months)->diffInDays($now);
|
||||
|
||||
$parts = [];
|
||||
if ($years > 0) $parts[] = $years . ' ساله';
|
||||
if ($months > 0) $parts[] = $months . ' ماهه';
|
||||
if ($days > 0 && $years == 0) $parts[] = $days . ' روزه';
|
||||
|
||||
return implode(' و ', $parts) ?: 'تازه متولد';
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'type' => $this->type,
|
||||
'gender' => $this->gender,
|
||||
'breed' => $this->breed,
|
||||
'weight' => $this->weight,
|
||||
'sterilized' => $this->sterilized,
|
||||
'birthday' => verta($this->birthday)->format('%Y/%m/%d - H:i'),
|
||||
'age' => $this->calculateAge($this->birthday),
|
||||
'owner' => $this->relationLoaded('owner') ? $this->owner->only(['id','fullname']) : null,
|
||||
'created_at' => verta($this->created_at)->format('%Y/%m/%d - H:i'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Panel;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class RelationWordResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'wordRelated' => $this->relatedWord?->word,
|
||||
'wordRelated_id' => $this->relatedWord?->id,
|
||||
'description' => $this->description,
|
||||
'relation_type' => $this->relation_type,
|
||||
'created_at' => verta($this->created_at)->format('%d %B %Y %H:%M:%S'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ReportResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'document' => $this->relationLoaded('document') ? $this->document->only(['id','code']) : null,
|
||||
'status' => $this->status,
|
||||
'body' => $this->body,
|
||||
'doctor' => $this->relationLoaded('doctor') ? $this->doctor->only(['id','fullname']) : null,
|
||||
'submitted_at' => verta($this->submitted_at)->format('%Y/%m/%d - H:i'),
|
||||
'submitted_at_form' => $this->submitted_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class RoleResource 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,
|
||||
'label' => $this->label,
|
||||
'created_at' => verta($this->created_at)->format('%d %B %Y %H:%M:%S'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SessionsIndexResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'ip' => $this->ip_address,
|
||||
'user_agent' => $this->user_agent,
|
||||
"last_activity" => $this->generateLastTime(),
|
||||
];
|
||||
}
|
||||
|
||||
private function generateLastTime()
|
||||
{
|
||||
$timestamp = $this->last_activity;
|
||||
|
||||
$carbon = Carbon::createFromTimestamp($timestamp);
|
||||
return verta($carbon)->format('%Y/%m/%d - H:i');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'username' => $this->username,
|
||||
'phone' => $this->phone,
|
||||
'fullname' => $this->fullname,
|
||||
'level' => $this->level,
|
||||
'email' => $this->email,
|
||||
'created_at' => verta($this->created_at)->format('%d %B %Y %H:%M:%S'),
|
||||
'profile_url' => $this->profile_url,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserShortResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'username' => $this->username,
|
||||
'phone' => $this->phone,
|
||||
'fullname' => $this->fullname,
|
||||
'level' => $this->level,
|
||||
'email' => $this->email,
|
||||
'profile_url' => $this->profile_url,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user