<?php

namespace App\Http\Resources;

use App\Models\Package as PackageModel;
use Illuminate\Http\Resources\Json\JsonResource;

class PackingList extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'reference_no' => $this->reference_no,
            'confirmed' => (int)$this->confirmed,
            'packages' => Package::collection(PackageModel::where('list_id', $this->id)->get())
        ];
    }
}
