mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-13 05:11:04 +03:30
fix some problems
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Services\Media\Resources\MediaResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ItemResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'udi' => $this->udi,
|
||||
'size' => $this->size,
|
||||
'specific' => $this->specific,
|
||||
'repair' => $this->repair,
|
||||
'status' => $this->status,
|
||||
'creator_id' => $this->creator_id,
|
||||
'creator' => UserResource::make($this->whenLoaded('creator')),
|
||||
'user_id' => $this->user_id,
|
||||
'user' => UserResource::make($this->whenLoaded('user')),
|
||||
'package' => PackageResource::make($this->whenLoaded('package')),
|
||||
'transfers' => TransferResource::collection($this->whenLoaded('transfers')),
|
||||
'files' => MediaResource::collection($this->media),
|
||||
'thumbnail' => $this->getFirstMediaUrl('main_images', 'thumbnail'),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Services\Media\Resources\MediaResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class MedicalCenterResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray( $request )
|
||||
{
|
||||
return [
|
||||
'id' => $this->id ,
|
||||
'name' => $this->name ,
|
||||
'address' => $this->address ,
|
||||
'phone_number' => $this->phone_number ,
|
||||
'city' => $this->when( $this->city , $this->city ),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Services\Media\Resources\MediaResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PackageResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'note' => $this->note,
|
||||
'verified' => $this->verified,
|
||||
'creator_id' => $this->creator_id,
|
||||
'creator' => UserResource::make($this->whenLoaded('creator')),
|
||||
'user_id' => $this->user_id,
|
||||
'user' => UserResource::make($this->whenLoaded('user')),
|
||||
'items' => ItemResource::collection($this->whenLoaded('items')),
|
||||
'transfers' => TransferResource::collection($this->whenLoaded('transfers')),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Services\Media\Resources\MediaResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TestResultResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray( $request )
|
||||
{
|
||||
return [
|
||||
'id' => $this->id ,
|
||||
'info' => $this->info ,
|
||||
'cycle_number' => $this->cycle_number ,
|
||||
'date' => $this->date ,
|
||||
'result' => $this->result ,
|
||||
'description' => $this->description ,
|
||||
'verified' => $this->verified ,
|
||||
'device_id' => $this->device_id ,
|
||||
'user_id' => $this->user_id ,
|
||||
'test_type_id' => $this->test_type_id ,
|
||||
'test_type' => $this->when( $this->test_type , $this->test_type ) ,
|
||||
'inputs' => $this->when( $this->inputs , $this->inputs ) ,
|
||||
'options' => $this->when( $this->options , $this->options ) ,
|
||||
'device_label' => $this->when( $this->device_label , $this->device_label ) ,
|
||||
'input_values' => $this->when( $this->input_values , $this->input_values ) ,
|
||||
'user' => UserResource::make( $this->whenLoaded( 'user' ) ) ,
|
||||
'files' => MediaResource::collection( $this->media ) ,
|
||||
'thumbnail' => $this->getFirstMediaUrl( 'main_images' , 'thumbnail' ) ,
|
||||
'created_at' => $this->created_at ,
|
||||
'updated_at' => $this->updated_at
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TransferResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'from_date' => $this->from_date,
|
||||
'to_date' => $this->to_date,
|
||||
'status' => $this->status,
|
||||
'user_id' => $this->user_id,
|
||||
'user' => UserResource::make($this->whenLoaded('user')),
|
||||
'transferable' => $this->resourceFinder(),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at
|
||||
];
|
||||
}
|
||||
|
||||
private function resourceFinder()
|
||||
{
|
||||
if ($this->whenLoaded('transferable')) {
|
||||
if ($this->transferable_type == "App\\Package"){
|
||||
return PackageResource::make($this->transferable);
|
||||
}elseif($this->transferable_type == "App\\Item"){
|
||||
return ItemResource::make($this->transferable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'status' => $this->status,
|
||||
'address' => $this->address,
|
||||
'gender' => $this->gender,
|
||||
'medical_center' => MedicalCenterResource::make($this->whenLoaded('medical_center')),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user