Files
shipping-portal/app/Http/Resources/SegmentResource.php
T

28 lines
911 B
PHP

<?php
namespace App\Http\Resources;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use Illuminate\Http\Resources\Json\JsonResource;
class SegmentResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'time_limit' => $this->when($this->whereHas('constants', function($query){
$query->where('reference', SegmentConstants::PAYMENT_ATTEMPT_DURATION_LIMIT);
}), $this->constants->where('reference', SegmentConstants::PAYMENT_ATTEMPT_DURATION_LIMIT)->first()),
'services' => CustomServiceTypeResource::collection($this->constants->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE))
];
}
}