'array' ]; protected $fillable = [ 'type', 'company_name', 'customer_nr', 'vat_id', 'tax_id', // Tax identification number 'global_id', // Global Location Number (GLN) or other identification 'legal_registration_id', // Legal registration ID 'url', 'email', 'phone', 'billing_address', 'payment_terms_id', 'status', 'logo', ]; /** * Set the billing address attribute. * * @param array $value * @return void */ public function setBillingAddressAttribute($value) { if (is_string($value)) { $value = json_decode($value, true); } $this->attributes['billing_address'] = json_encode([ 'line_one' => $value['line_one'] ?? '', 'line_two' => $value['line_two'] ?? '', 'city' => $value['city'] ?? '', 'postal_code' => $value['postal_code'] ?? '', 'country_code' => $value['country_code'] ?? 'DE', // Default to Germany ]); } /** * Get the billing address attribute. * * @return array */ public function getBillingAddressAttribute() { return json_decode($this->attributes['billing_address'], true) ?? [ 'line_one' => '', 'line_two' => '', 'city' => '', 'postal_code' => '', 'country_code' => 'DE', ]; } /** * Get the URL to the customer's logo. */ public function getLogoUrlAttribute() { if ($this->logo) { return asset('storage/' . $this->logo); } // Return null if no logo is set return null; } /** * Get the contacts for the customer. */ public function contacts() { return $this->hasMany(Contact::class); } /** * Get the payment term associated with the customer. */ public function paymentTerms() { return $this->belongsTo(PaymentTerms::class); } /** * Get the notes for the customer */ public function notes() { return $this->morphMany(Note::class, 'notable'); } }