mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 23:31:06 +03:30
42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?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);
|
|
}
|
|
}
|
|
}
|
|
}
|