<?php

namespace App\Http\Resources;

use App\Models\Address;
use App\Models\Company;
use Illuminate\Http\Resources\Json\JsonResource;

class OrderResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'marking' => $this->order_number,
            'company' => Company::where('id', $this->company_id)->first(),
            'warehouse_id' => $this->warehouse_id,
            'address' => new AddressResource(Address::where('id', $this->address_id)->first()),
            'complete' => (int)$this->complete,
            'date' => $this->created_at->format('d/m/Y')
        ];
    }

}
