From beebee6b82377724ea388d563a4692b32bcc3c59 Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Tue, 9 Dec 2025 09:09:23 +0100 Subject: [PATCH] BF self to static, which allows extendable models --- src/Models/Product.php | 4 ++-- src/Models/ProductCategory.php | 6 +++--- src/Traits/HasProductRelations.php | 2 +- workbench/app/Models/Product.php | 5 +++++ 4 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 workbench/app/Models/Product.php diff --git a/src/Models/Product.php b/src/Models/Product.php index 3867aaf..3c72eca 100644 --- a/src/Models/Product.php +++ b/src/Models/Product.php @@ -134,12 +134,12 @@ class Product extends Model implements Purchasable, Cartable public function parent() { - return $this->belongsTo(self::class, 'parent_id'); + return $this->belongsTo(static::class, 'parent_id'); } public function children(): HasMany { - return $this->hasMany(self::class, 'parent_id'); + return $this->hasMany(static::class, 'parent_id'); } public function attributes(): HasMany diff --git a/src/Models/ProductCategory.php b/src/Models/ProductCategory.php index acd6f86..ed30f45 100644 --- a/src/Models/ProductCategory.php +++ b/src/Models/ProductCategory.php @@ -76,19 +76,19 @@ class ProductCategory extends Model public function parent(): BelongsTo { - return $this->belongsTo(self::class, 'parent_id'); + return $this->belongsTo(static::class, 'parent_id'); } public function children(): HasMany { - return $this->hasMany(self::class, 'parent_id') + return $this->hasMany(static::class, 'parent_id') ->where('is_visible', true) ->orderBy('sort_order'); } public function allChildren(): HasMany { - return $this->hasMany(self::class, 'parent_id') + return $this->hasMany(static::class, 'parent_id') ->orderBy('sort_order'); } diff --git a/src/Traits/HasProductRelations.php b/src/Traits/HasProductRelations.php index 517f77b..11ce2ee 100644 --- a/src/Traits/HasProductRelations.php +++ b/src/Traits/HasProductRelations.php @@ -10,7 +10,7 @@ trait HasProductRelations public function productRelations(): BelongsToMany { return $this->belongsToMany( - self::class, + static::class, config('shop.tables.product_relations', 'product_relations'), 'product_id', 'related_product_id' diff --git a/workbench/app/Models/Product.php b/workbench/app/Models/Product.php new file mode 100644 index 0000000..16bfd43 --- /dev/null +++ b/workbench/app/Models/Product.php @@ -0,0 +1,5 @@ +