'integer', 'meta' => 'object', ]; public function __construct(array $attributes = []) { parent::__construct($attributes); $this->setTable(config('shop.tables.product_purchases', 'product_purchases')); } public function purchasable() { return $this->morphTo(); } // Backward compatibility - user accessor public function user() { if ($this->purchasable_type === config('auth.providers.users.model', \Workbench\App\Models\User::class)) { return $this->purchasable(); } return null; } // Backward compatibility accessor public function getUserIdAttribute() { if ($this->purchasable_type === config('auth.providers.users.model', \Workbench\App\Models\User::class)) { return $this->purchasable_id; } return null; } public function product() { return $this->belongsTo(config('shop.models.product', Product::class)); } public static function scopeFromCart($query, $cartId) { return $query->where('cart_id', $cartId); } public static function scopeInCart($query) { return $query->where('status', 'cart'); } public static function scopeCompleted($query) { return $query->where('status', 'completed'); } protected static function booted() { static::created(function ($productPurchase) { if ($productPurchase->status === 'completed' && $product = $productPurchase->product) { $product->callActions('purchased', $productPurchase); } }); } }