diff --git a/app/Interfaces/ProductItem.php b/app/Interfaces/ProductItem.php index 56ec556..5556c3c 100644 --- a/app/Interfaces/ProductItem.php +++ b/app/Interfaces/ProductItem.php @@ -6,10 +6,6 @@ use Illuminate\Support\Collection; interface ProductItem { - public function products(); - - public function supplied(); - /** * Return the traffic inclusion with the service * diff --git a/app/Models/Product.php b/app/Models/Product.php index 8459327..22fcb62 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -96,7 +96,9 @@ class Product extends Model implements IDs public function translate() { return $this->hasOne(ProductTranslate::class) - ->where('language_id',(Auth::user() && Auth::user()->language_id) ? Auth::user()->language_id : config('site')->language_id); + ->where('language_id',(Auth::user() && Auth::user()->language_id) + ? Auth::user()->language_id + : config('site')->language_id); } /** @@ -290,11 +292,12 @@ class Product extends Model implements IDs /** * Suppliers product * - * @return Model|null + * @return Model + * @todo make internal as other values off this attribute are used, not the model itself */ - public function getSuppliedAttribute(): ?Model + public function getSuppliedAttribute(): Model { - return $this->type->supplied ? $this->type->supplied : NULL; + return $this->type->supplied; } /** diff --git a/app/Models/Product/Broadband.php b/app/Models/Product/Broadband.php index 46e444b..d26b013 100644 --- a/app/Models/Product/Broadband.php +++ b/app/Models/Product/Broadband.php @@ -34,17 +34,8 @@ final class Broadband extends Type implements ProductItem // The model that is referenced when this product is ordered protected string $order_model = ServiceBroadband::class; - /* RELATIONS */ - - /** - * The offering supplied with this product - * - * @return \Illuminate\Database\Eloquent\Relations\HasOne - */ - public function supplied() - { - return $this->hasOne(SupplierBroadband::class,'id','supplier_item_id'); - } + // The model that the supplier supplies + const SupplierModel = SupplierBroadband::class; /* INTERFACES */ diff --git a/app/Models/Product/Domain.php b/app/Models/Product/Domain.php index 941ec68..90181ee 100644 --- a/app/Models/Product/Domain.php +++ b/app/Models/Product/Domain.php @@ -31,17 +31,8 @@ final class Domain extends Type implements ProductItem // The model that is referenced when this product is ordered protected string $order_model = ServiceDomain::class; - /* RELATIONS */ - - /** - * The offering supplied with this product - * - * @return \Illuminate\Database\Eloquent\Relations\HasOne - */ - public function supplied() - { - return $this->hasOne(SupplierDomain::class,'id','supplier_item_id'); - } + // The model that the supplier supplies + const SupplierModel = SupplierDomain::class; /* INTERFACES */ diff --git a/app/Models/Product/Email.php b/app/Models/Product/Email.php index bd98f00..018332d 100644 --- a/app/Models/Product/Email.php +++ b/app/Models/Product/Email.php @@ -15,17 +15,8 @@ final class Email extends Type implements ProductItem // The model that is referenced when this product is ordered protected string $order_model = ServiceEmail::class; - /* RELATIONS */ - - /** - * The offering supplied with this product - * - * @return \Illuminate\Database\Eloquent\Relations\HasOne - */ - public function supplied() - { - return $this->hasOne(SupplierEmail::class,'id','supplier_item_id'); - } + // The model that the supplier supplies + const SupplierModel = SupplierEmail::class; /* INTERFACES */ diff --git a/app/Models/Product/Generic.php b/app/Models/Product/Generic.php index 7173b97..e2a1984 100644 --- a/app/Models/Product/Generic.php +++ b/app/Models/Product/Generic.php @@ -15,17 +15,8 @@ final class Generic extends Type implements ProductItem // The model that is referenced when this product is ordered protected string $order_model = ServiceGeneric::class; - /* RELATIONS */ - - /** - * The offering supplied with this product - * - * @return \Illuminate\Database\Eloquent\Relations\HasOne - */ - public function supplied() - { - return $this->hasOne(SupplierGeneric::class,'id','supplier_item_id'); - } + // The model that the supplier supplies + const SupplierModel = SupplierGeneric::class; /* INTERFACES */ diff --git a/app/Models/Product/Host.php b/app/Models/Product/Host.php index 570aeba..8f8ece6 100644 --- a/app/Models/Product/Host.php +++ b/app/Models/Product/Host.php @@ -15,17 +15,8 @@ final class Host extends Type implements ProductItem // The model that is referenced when this product is ordered protected string $order_model = ServiceHost::class; - /* RELATIONS */ - - /** - * The offering supplied with this product - * - * @return \Illuminate\Database\Eloquent\Relations\HasOne - */ - public function supplied() - { - return $this->hasOne(SupplierHost::class,'id','supplier_item_id'); - } + // The model that the supplier supplies + const SupplierModel = SupplierHost::class; /* INTERFACES */ diff --git a/app/Models/Product/Phone.php b/app/Models/Product/Phone.php index 8f43d99..6daa9ef 100644 --- a/app/Models/Product/Phone.php +++ b/app/Models/Product/Phone.php @@ -42,17 +42,8 @@ final class Phone extends Type implements ProductItem // The model that is referenced when this product is ordered protected string $order_model = ServicePhone::class; - /* RELATIONS */ - - /** - * The offering supplied with this product - * - * @return \Illuminate\Database\Eloquent\Relations\HasOne - */ - public function supplied() - { - return $this->hasOne(SupplierPhone::class,'id','supplier_item_id'); - } + // The model that the supplier supplies + const SupplierModel = SupplierPhone::class; /* INTERFACES */ diff --git a/app/Models/Product/SSL.php b/app/Models/Product/SSL.php index 3f8dcbe..1e6f37d 100644 --- a/app/Models/Product/SSL.php +++ b/app/Models/Product/SSL.php @@ -15,17 +15,8 @@ final class SSL extends Type implements ProductItem // The model that is referenced when this product is ordered protected string $order_model = ServiceSSL::class; - /* RELATIONS */ - - /** - * The offering supplied with this product - * - * @return \Illuminate\Database\Eloquent\Relations\HasOne - */ - public function supplied() - { - return $this->hasOne(SupplierSSL::class,'id','supplier_item_id'); - } + // The model that the supplier supplies + const SupplierModel = SupplierSSL::class; /* INTERFACES */ diff --git a/app/Models/Product/Type.php b/app/Models/Product/Type.php index 9ec6d43..589a9ed 100644 --- a/app/Models/Product/Type.php +++ b/app/Models/Product/Type.php @@ -27,6 +27,16 @@ abstract class Type extends Model return $this->morphMany(Product::class, null,'model','model_id'); } + /** + * The offering supplied with this product + * + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function supplied() + { + return $this->hasOne(static::SupplierModel,'id','supplier_item_id'); + } + /** * This will return the category of the product (eg: domain, hosting, etc) which is the basis for all * other logic of these types.