ldc-mesbr-app/app/Http/Resources/CouponsResource.php

42 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2021-04-27 17:29:47 +02:00
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class CouponsResource extends JsonResource
{
/**
* Transform the resource collection into an array.
*
2025-04-03 09:30:16 +02:00
* @param \Illuminate\Http\Request $request
2021-04-27 17:29:47 +02:00
* @return array
*/
public function toArray($request)
{
$coupon = [
2021-04-27 17:29:47 +02:00
'code' => $this->coupon_code,
'name' => $this->coupon_name,
'value' => $this->coupon_value,
'used' => isset($this->isUsed) ? $this->isUsed : false,
'desktop_image_available' => $this->returnUrl($this->coupon_thumbnail1),
'desktop_image_unavailable' => $this->returnUrl($this->coupon_thumbnail2),
'mobile_image_available' => $this->returnUrl($this->coupon_thumbnail3),
'mobile_image_unavailable' => $this->returnUrl($this->coupon_thumbnail4),
'validity_text' => $this->coupon_validity_text
2021-04-27 17:29:47 +02:00
];
if (isset($this->isUsed)){
return array_merge($coupon, [
'used' => $this->isUsed,
]);
}
return $coupon;
2021-04-27 17:29:47 +02:00
}
private function returnUrl($assets)
{
return !empty($assets) ? config('app.url') . "/$assets" : null;
}
}