Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ItemInputResource | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| toArray | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Item\Resource; |
| 4 | |
| 5 | use App\Models\Transferable\Transferable; |
| 6 | use Domain\Integration\Resources\IntegrationResource; |
| 7 | use Domain\Product\Resources\ProductResource; |
| 8 | use Domain\StockIO\Resources\StockIoInputInvoiceResource; |
| 9 | use Domain\Storage\Resources\StorageResource; |
| 10 | use Illuminate\Http\Request; |
| 11 | use Illuminate\Http\Resources\Json\JsonResource; |
| 12 | |
| 13 | /** |
| 14 | * @property float $amount |
| 15 | * @property int $id |
| 16 | * @property string $created_at |
| 17 | * @property string $updated_at |
| 18 | */ |
| 19 | class ItemInputResource extends JsonResource |
| 20 | { |
| 21 | /** |
| 22 | * @param Request $request |
| 23 | * @return array |
| 24 | */ |
| 25 | public function toArray(Request $request): array |
| 26 | { |
| 27 | $transferable_id = $this->transferable_id; |
| 28 | |
| 29 | if (is_null($transferable_id)) { |
| 30 | $transferable_id = Transferable::query() |
| 31 | ->where('transferable_id', $this->itemable_id) |
| 32 | ->where('transferable_type', $this->itemable_type) |
| 33 | ->select('id') |
| 34 | ->first(); |
| 35 | |
| 36 | $transferable_id = $transferable_id->id; |
| 37 | } |
| 38 | |
| 39 | return [ |
| 40 | 'id' => $this->id, |
| 41 | 'storage' => StorageResource::make($this->whenLoaded('storage')), |
| 42 | 'product' => ProductResource::make($this->whenLoaded('product')), |
| 43 | 'amount' => $this->amount, |
| 44 | 'transferable_id' => $transferable_id, |
| 45 | 'integration' => IntegrationResource::make($this->whenLoaded('integration')), |
| 46 | 'created_at' => (string)$this->created_at, |
| 47 | 'updated_at' => (string)$this->updated_at, |
| 48 | ]; |
| 49 | } |
| 50 | } |