adrema/app/Payment/SubscriptionResource.php

50 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2021-07-04 01:44:41 +02:00
<?php
namespace App\Payment;
2023-05-02 23:13:00 +02:00
use App\Lib\HasMeta;
2021-07-04 01:44:41 +02:00
use Illuminate\Http\Resources\Json\JsonResource;
2022-01-02 12:32:57 +01:00
/**
* @mixin Subscription
*/
2021-07-04 01:44:41 +02:00
class SubscriptionResource extends JsonResource
{
2023-05-02 23:13:00 +02:00
use HasMeta;
2021-07-04 01:44:41 +02:00
/**
* Transform the resource into an array.
*
2022-03-11 20:19:17 +01:00
* @param \Illuminate\Http\Request $request
*
2021-07-04 01:44:41 +02:00
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'fee_id' => $this->fee_id,
'fee_name' => $this->fee->name,
2022-12-13 23:11:32 +01:00
'amount_human' => number_format($this->getAmount() / 100, 2, ',', '.').' €',
'amount' => $this->getAmount(),
2022-12-14 00:23:03 +01:00
'split' => $this->split,
2022-12-13 23:11:32 +01:00
'children' => SubscriptionChildResource::collection($this->whenLoaded('children')),
2022-12-14 23:20:05 +01:00
'for_promise' => $this->for_promise,
2021-07-04 01:44:41 +02:00
];
}
2023-05-02 23:13:00 +02:00
/**
* @return array<string, mixed>
*/
public static function meta(): array
{
return [
'links' => [
'index' => route('subscription.index'),
'create' => route('subscription.create'),
],
];
}
2021-07-04 01:44:41 +02:00
}