mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-12 07:01:06 +03:30
fix some problems
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user