-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlanResource.php
42 lines (38 loc) · 1.26 KB
/
PlanResource.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Err0r\Larasub\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PlanResource extends JsonResource
{
public function __construct($resource, private $subscription = null)
{
parent::__construct($resource);
}
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'slug' => $this->slug,
'name' => $this->name,
'description' => $this->description,
'is_active' => $this->is_active,
'price' => $this->price,
'currency' => $this->currency,
'reset_period' => $this->reset_period,
'reset_period_type' => $this->reset_period_type,
'sort_order' => $this->sort_order,
'features' => $this->whenLoaded('features', function () {
return $this->features->map(function ($feature) {
return new (config('larasub.resources.plan_feature'))($feature, $this->subscription);
});
}),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}