*/ protected $fillable = [ 'name', 'email', ]; /** * The attributes that are appended with attribute getters. * * @var string[] */ protected $appends = [ 'created', 'street', 'city' ]; /** * Deliver the customer's address as street directly with the model. */ public function getStreetAttribute(): string { if (is_null($this->address)) { return ''; } return $this->address->address; } /** * Deliver the customer's address as city directly with the model. */ public function getCityAttribute(): string { if (is_null($this->address)) { return ''; } return $this->address->city; } /** * Get the created_at attribute in local time format. */ public function getCreatedAttribute(): string { return $this->created_at->format('d.m.Y'); } /** * Get the invoice address. */ public function address(): HasOne { return $this->hasOne(Address::class)->ofMany([], function (Builder $query) { $query->where('is_address', '=', true); }); } /** * Get the delivery address. */ public function delivery(): HasOne { return $this->hasOne(Address::class)->ofMany([], function (Builder $query) { $query->where('is_delivery', '=', true); }); } /** * Get all customer's addresses. */ public function addresses(): HasMany { return $this->hasMany(Address::class); } }