Files
portal/app/Http/Resources/StateResource.php
T
2022-04-19 14:57:38 +08:00

30 lines
883 B
PHP

<?php
namespace App\Http\Resources;
use App\Models\SegmentConstant;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Classes\ValueObjects\Constants\SegmentConstants;
class StateResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
$segmentConstantObject = SegmentConstant::where('reference', SegmentConstants::STATE_RATE)->get();
$segmentConstant = $segmentConstantObject->isEmpty() ? [] : (array)$segmentConstantObject->first()->value;
return [
'id' => $this->id,
'name' => $this->name,
'country' => $this->country,
'stateCharges' => array_key_exists($this->id, $segmentConstant) ? $segmentConstant[$this->id] : null,
];
}
}