Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| PlanFeatureResource | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| toArray | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Resources\v2; |
| 4 | |
| 5 | use Illuminate\Http\Request; |
| 6 | use Illuminate\Http\Resources\Json\JsonResource; |
| 7 | |
| 8 | /** |
| 9 | * Resource for transforming PlanFeature (pivot) models for API responses. |
| 10 | * |
| 11 | * @property string $_id The plan feature ID |
| 12 | * @property string $plan_id The plan ID |
| 13 | * @property string $feature_id The feature ID |
| 14 | * @property mixed $value The custom value for this feature on this plan |
| 15 | * @property bool $is_enabled Whether this feature is enabled |
| 16 | * @property \App\Http\Models\Feature|null $feature The feature relation |
| 17 | * @property \Carbon\Carbon|null $created_at When the assignment was created |
| 18 | * @property \Carbon\Carbon|null $updated_at When the assignment was last updated |
| 19 | */ |
| 20 | class PlanFeatureResource extends JsonResource |
| 21 | { |
| 22 | /** |
| 23 | * Transform the resource into an array. |
| 24 | * |
| 25 | * @return array<string, mixed> |
| 26 | */ |
| 27 | public function toArray(Request $request): array |
| 28 | { |
| 29 | return [ |
| 30 | 'id' => (string) $this->_id, |
| 31 | 'plan_id' => $this->plan_id, |
| 32 | 'feature_id' => $this->feature_id, |
| 33 | 'value' => $this->value, |
| 34 | 'is_enabled' => (bool) $this->is_enabled, |
| 35 | 'feature' => $this->whenLoaded('feature', function () { |
| 36 | return new FeatureResource($this->feature); |
| 37 | }), |
| 38 | 'created_at' => $this->created_at?->timestamp, |
| 39 | 'updated_at' => $this->updated_at?->timestamp, |
| 40 | ]; |
| 41 | } |
| 42 | } |