*/ protected $fillable = [ 'firstname', 'lastname', 'address', 'postcode', 'phone', 'email', 'city', 'civility', 'status', 'payementType', 'customer_id', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'civility' => ContactFormCivility::class, 'status' => OrderStatus::class, 'payementType' => OrderType::class, ]; // * METHODS /** * Export the model data to a Formatted Arcadia Data array. * * @return array> */ public function exportToOrderMailData(): array { return [ 'ref' => $this->ref, 'lastname' => $this->lastname, 'firstname' => $this->firstname, 'address' => $this->address, 'postcode' => $this->postcode, 'city' => $this->city, 'email' => $this->email, 'phone' => $this->phone ?? '', 'items' => $this->sellItems()->withPivot('quantity')->get()->map(function (SellItem $item) { // @phpstan-ignore-next-line $item->typeCustom = $item->type->toArray()[$item->type->name()]; return $item; })->toArray(), ]; } // * RELATIONSHIPS /** * Get all of the items that are assigned this order. */ public function sellItems(): BelongsToMany { return $this->belongsToMany(SellItem::class)->withPivot('quantity'); } /** * Get the customer that are assigned this order. */ public function customer(): BelongsTo { return $this->belongsTo(Customer::class); } /** * Get the delivery address that are assigned this order. */ public function deliveryAddress(): HasOne { return $this->hasOne(DeliveryAddress::class); } }