Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| ProductSimpleResource | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| toArray | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Product\Resources; |
| 4 | |
| 5 | use App\Models\Integration\Integration; |
| 6 | use Domain\Category\Resources\FamilyResource; |
| 7 | use Domain\Integration\Resources\IntegrationResource; |
| 8 | use Domain\UnitMeasurement\Resources\UnitMeasurementResource; |
| 9 | use Illuminate\Database\Eloquent\Model; |
| 10 | use Illuminate\Http\Request; |
| 11 | use Illuminate\Http\Resources\Json\JsonResource; |
| 12 | |
| 13 | /** |
| 14 | * @property string $integration_date |
| 15 | * @property string $integration_barcode |
| 16 | * @property string $integration_code |
| 17 | * @property int $id |
| 18 | * @property Model|null $pivot |
| 19 | * @property string $description |
| 20 | * @property mixed $integration_product |
| 21 | * @property Integration $integration |
| 22 | */ |
| 23 | class ProductSimpleResource extends JsonResource |
| 24 | { |
| 25 | |
| 26 | public function toArray(Request $request): array |
| 27 | { |
| 28 | return [ |
| 29 | 'id' => $this->id, |
| 30 | 'description' => $this->description, |
| 31 | 'priority_field' => $this->priority_field, |
| 32 | 'priority_order' => $this->priority_order, |
| 33 | 'integration' => IntegrationResource::make($this->whenLoaded('integration')), |
| 34 | 'amount' => $this->whenPivotLoaded($this->pivot?->getTable(), fn() => $this->pivot->getAttribute('amount')), |
| 35 | 'measure' => ProductMeasureResource::make($this->whenLoaded('measure')), |
| 36 | 'family' => FamilyResource::make($this->whenLoaded('family')), |
| 37 | 'unit_measurement' => UnitMeasurementResource::make($this->whenLoaded('unitMeasurement')), |
| 38 | 'created_at' => $this->created_at, |
| 39 | 'updated_at' => $this->updated_at |
| 40 | ]; |
| 41 | } |
| 42 | |
| 43 | } |