Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| AddressPrintResource | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| toArray | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Address\Resources; |
| 4 | |
| 5 | use App\Models\Transferable\Transferable; |
| 6 | use Domain\Address\Services\AddressHierarchyService; |
| 7 | use Illuminate\Http\Request; |
| 8 | use Illuminate\Http\Resources\Json\JsonResource; |
| 9 | use Illuminate\Support\Collection; |
| 10 | |
| 11 | /** |
| 12 | * @property int $id |
| 13 | * @property Transferable|null $transferable |
| 14 | * @property string $name |
| 15 | * @property bool $can_store |
| 16 | * @property bool $can_remove |
| 17 | * @property Collection $items |
| 18 | * @property int $status |
| 19 | * @property int $order |
| 20 | */ |
| 21 | class AddressPrintResource extends JsonResource |
| 22 | { |
| 23 | public function toArray(Request $request): array |
| 24 | { |
| 25 | return [ |
| 26 | 'id' => $this->id, |
| 27 | 'name' => $this->name, |
| 28 | 'sector' => $this->sector->value, |
| 29 | 'hierarchy' => $this->whenLoaded('parent', (new AddressHierarchyService())->get($this->resource)), |
| 30 | 'children' => AddressPrintResource::collection($this->whenLoaded('children')), |
| 31 | ]; |
| 32 | } |
| 33 | } |