mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
30 lines
883 B
PHP
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,
|
|
];
|
|
}
|
|
}
|