self::ADDRESS_TYPE_BILLING, ]; /** * The "booted" method of the model. * * @return void */ protected static function boot(): void { static::addGlobalScope('address_type', function (Builder $builder) { $builder->whereIn('address_type', [ self::ADDRESS_TYPE_BILLING, self::ADDRESS_TYPE_SHIPPING, ]); }); static::creating(static function ($address) { switch ($address->address_type) { case CartAddress::ADDRESS_TYPE_BILLING: $address->address_type = self::ADDRESS_TYPE_BILLING; break; case CartAddress::ADDRESS_TYPE_SHIPPING: $address->address_type = self::ADDRESS_TYPE_SHIPPING; break; } }); parent::boot(); } /** * Get the order record associated with the address. */ public function order(): BelongsTo { return $this->belongsTo(Order::class); } /** * Create a new factory instance for the model. * * @return Factory */ protected static function newFactory(): Factory { return OrderAddressFactory::new(); } }