55 lines
2.2 KiB
PHP
55 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use App\Libraries\StaticContents;
|
|
use App\Helpers\StringHelper;
|
|
use App\Helpers\CurrentUserHelper;
|
|
use App\Libraries\S3;
|
|
|
|
class PromotionResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$this->withoutWrapping();
|
|
|
|
|
|
$stations = array();
|
|
|
|
foreach ($this->promotionStations as $key => $value) {
|
|
$stations[] = array(
|
|
'station_uuid' => $value->station->station_uuid,
|
|
'description' => $value->station->description,
|
|
);
|
|
}
|
|
|
|
return [
|
|
'promotion_uuid' => $this->promotion_uuid,
|
|
'stations' => $stations,
|
|
'title' => $this->title,
|
|
'description' => $this->description,
|
|
'image' => $this->image != '' ? S3::public_path($this->image) : null,
|
|
'date_start' => $this->date_start,
|
|
'date_end' => $this->date_end,
|
|
'is_toppromotion' => $this->is_toppromotion,
|
|
'is_gps' => $this->is_gps,
|
|
'promo_type' => array(
|
|
'id' => $this->promo_type,
|
|
'name' => StaticContents::promo_type($this->promo_type)
|
|
),
|
|
'status' => StringHelper::check_date_if_between($this->date_start,$this->date_end),
|
|
'created_at' => $this->created_at != null ? $this->created_at->toDateTimeString() : null,
|
|
'updated_at' => ($this->updated_at != null && $this->created_at != $this->updated_at) ? $this->updated_at->toDateTimeString() : null,
|
|
'created_by' => $this->created_by != 0 ? CurrentUserHelper::getAdminName($this->created_by) : null,
|
|
'updated_by' => $this->updated_by != 0 ? CurrentUserHelper::getAdminName($this->updated_by) : null,
|
|
];
|
|
}
|
|
}
|