From 48d89d338ce08b4be6158f180ab035421aaff03d Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Mon, 4 Oct 2021 14:09:51 +0200 Subject: [PATCH] refactor, better class namespace intergration --- app/Models/Shop/Article.php | 9 ++++----- app/Models/Shop/ArticleNature.php | 2 +- app/Models/Shop/ArticlePrice.php | 6 +++--- app/Models/Shop/Category.php | 4 ++-- app/Models/Shop/Customer.php | 4 ++-- app/Models/Shop/CustomerAddress.php | 4 ++-- app/Models/Shop/DistributionChannel.php | 4 ++-- app/Models/Shop/Invoice.php | 4 ++-- app/Models/Shop/InvoiceItem.php | 4 ++-- app/Models/Shop/Merchandise.php | 2 +- app/Models/Shop/Offer.php | 6 +++--- app/Models/Shop/Order.php | 4 ++-- app/Models/Shop/OrderPayment.php | 2 +- app/Models/Shop/Package.php | 6 +++--- app/Models/Shop/Price.php | 8 ++++---- app/Models/Shop/PriceGenericCategory.php | 4 ++-- app/Models/Shop/PriceList.php | 12 ++++++------ app/Models/Shop/PriceListValue.php | 6 +++--- app/Models/Shop/Shelve.php | 10 +++++----- app/Models/Shop/Tag.php | 10 +++++----- app/Models/Shop/TagGroup.php | 4 ++-- app/Models/Shop/Tariff.php | 6 +++--- app/Models/Shop/TariffUnity.php | 2 +- app/Models/Shop/Tax.php | 2 +- app/Models/Shop/Unity.php | 17 ++++------------- app/Models/Shop/Variation.php | 4 ++-- 26 files changed, 68 insertions(+), 78 deletions(-) diff --git a/app/Models/Shop/Article.php b/app/Models/Shop/Article.php index b7382758..0fdabaa3 100644 --- a/app/Models/Shop/Article.php +++ b/app/Models/Shop/Article.php @@ -6,7 +6,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Spatie\Image\Manipulations; - use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; @@ -27,7 +26,7 @@ class Article extends Model implements HasMedia public function article_nature() { - return $this->belongsTo('App\Models\Shop\ArticleNature'); + return $this->belongsTo(ArticleNature::class); } public function images() @@ -42,12 +41,12 @@ class Article extends Model implements HasMedia public function invoiceItems() { - return $this->hasMany('App\Models\Shop\InvoiceItem'); + return $this->hasMany(InvoiceItem::class); } public function prices() { - return $this->hasMany('App\Models\Shop\Price'); + return $this->hasMany(Price::class); } public function product() @@ -57,7 +56,7 @@ class Article extends Model implements HasMedia public function tags() { - return $this->morphToMany('App\Models\Shop\Tag', 'taggable'); + return $this->morphToMany(Tag::class, 'taggable'); } public function scopeByArticle($query, $id) diff --git a/app/Models/Shop/ArticleNature.php b/app/Models/Shop/ArticleNature.php index 5d086206..fba0982f 100644 --- a/app/Models/Shop/ArticleNature.php +++ b/app/Models/Shop/ArticleNature.php @@ -17,6 +17,6 @@ class ArticleNature extends Model public function articles() { - return $this->hasMany('App\Models\Shop\Article'); + return $this->hasMany(Article::class); } } diff --git a/app/Models/Shop/ArticlePrice.php b/app/Models/Shop/ArticlePrice.php index b82d549c..d411a0bb 100644 --- a/app/Models/Shop/ArticlePrice.php +++ b/app/Models/Shop/ArticlePrice.php @@ -14,12 +14,12 @@ class ArticlePrice extends Model public function price() { - return $this->hasOne('App\Models\Price'); + return $this->hasOne(Price::class); } public function article_family() { - return $this->belongsTo('App\Models\ArticleNature'); + return $this->belongsTo(ArticleNature::class); } public function scopeByQuantity($query, $quantity) @@ -29,6 +29,6 @@ class ArticlePrice extends Model public function scopeByFamily($query, $id) { - return $query->where('article_family_value_id', $id); + return $query->where($this->table . '.article_family_value_id', $id); } } diff --git a/app/Models/Shop/Category.php b/app/Models/Shop/Category.php index 5bb782e3..5ce69da8 100644 --- a/app/Models/Shop/Category.php +++ b/app/Models/Shop/Category.php @@ -22,12 +22,12 @@ class Category extends Model public function Articles() { - return $this->morphedByMany('App\Models\Shop\Article', 'categorizable'); + return $this->morphedByMany(Article::class, 'categorizable'); } public function Shelves() { - return $this->morphedByMany('App\Models\Shop\Category', 'categorizable'); + return $this->morphedByMany(Category::class, 'categorizable'); } public function CategoryTree() diff --git a/app/Models/Shop/Customer.php b/app/Models/Shop/Customer.php index 693a6ca1..bd98dcd1 100644 --- a/app/Models/Shop/Customer.php +++ b/app/Models/Shop/Customer.php @@ -11,12 +11,12 @@ class Customer extends Model public function Invoices() { - return $this->hasMany('App\Models\Shop\Invoice'); + return $this->hasMany(Invoice::class); } public function Orders() { - return $this->hasMany('App\Models\Shop\Order'); + return $this->hasMany(Order::class); } public function User() diff --git a/app/Models/Shop/CustomerAddress.php b/app/Models/Shop/CustomerAddress.php index e872923d..06fcba6f 100644 --- a/app/Models/Shop/CustomerAddress.php +++ b/app/Models/Shop/CustomerAddress.php @@ -10,11 +10,11 @@ class CustomerAddress extends Model public function Customer() { - return $this->belongsTo('App\Models\Shop\Customer'); + return $this->belongsTo(Customer::class); } public function Orders() { - return $this->hasMany('App\Models\Shop\Order'); + return $this->hasMany(Order::class); } } diff --git a/app/Models/Shop/DistributionChannel.php b/app/Models/Shop/DistributionChannel.php index 42fd5399..7e05ba17 100644 --- a/app/Models/Shop/DistributionChannel.php +++ b/app/Models/Shop/DistributionChannel.php @@ -10,10 +10,10 @@ class DistributionChannel extends Model use HasRelationships; protected $guarded = ['id']; - protected $table = 'shop_article_families'; + protected $table = 'shop_distribution_channel'; public function tariff_generics() { - return $this->hasMany('App\Models\Shop\TariffGeneric'); + return $this->hasMany(TariffGeneric::class); } } diff --git a/app/Models/Shop/Invoice.php b/app/Models/Shop/Invoice.php index 64c83796..93fdf2c8 100644 --- a/app/Models/Shop/Invoice.php +++ b/app/Models/Shop/Invoice.php @@ -13,7 +13,7 @@ class Invoice extends Model */ public function InvoiceItems() { - return $this->hasMany('App\Models\Shop\InvoiceItem'); + return $this->hasMany(InvoiceItem::class); } /** @@ -21,6 +21,6 @@ class Invoice extends Model */ public function Customer() { - return $this->belongsTo('App\Models\Shop\Customer'); + return $this->belongsTo(Customer::class); } } diff --git a/app/Models/Shop/InvoiceItem.php b/app/Models/Shop/InvoiceItem.php index d0cba56b..3d0e8911 100644 --- a/app/Models/Shop/InvoiceItem.php +++ b/app/Models/Shop/InvoiceItem.php @@ -13,7 +13,7 @@ class InvoiceItem extends Model */ public function Product() { - return $this->belongsTo('App\Models\Shop\Product'); + return $this->belongsTo(Product::class); } /** @@ -21,6 +21,6 @@ class InvoiceItem extends Model */ public function Invoice() { - return $this->belongsTo('App\Models\Shop\Invoice'); + return $this->belongsTo(Invoice::class); } } diff --git a/app/Models/Shop/Merchandise.php b/app/Models/Shop/Merchandise.php index 795bcd7d..fe84c854 100644 --- a/app/Models/Shop/Merchandise.php +++ b/app/Models/Shop/Merchandise.php @@ -15,6 +15,6 @@ class Merchandise extends Model public function Articles() { - return $this->morphMany('App\Models\Shop\Article', 'product'); + return $this->morphMany(Article::class, 'product'); } } diff --git a/app/Models/Shop/Offer.php b/app/Models/Shop/Offer.php index 9afe63cd..cc8c584a 100644 --- a/app/Models/Shop/Offer.php +++ b/app/Models/Shop/Offer.php @@ -14,16 +14,16 @@ class Offer extends Model public function article() { - return $this->belongsTo('App\Models\Shop\Article'); + return $this->belongsTo(Article::class); } public function variation() { - return $this->belongsTo('App\Models\Shop\Variation'); + return $this->belongsTo(Variation::class); } public function tariff() { - return $this->belongsTo('App\Models\Shop\Tariff'); + return $this->belongsTo(Tariff::class); } } diff --git a/app/Models/Shop/Order.php b/app/Models/Shop/Order.php index dbf0fefe..7e3141e3 100644 --- a/app/Models/Shop/Order.php +++ b/app/Models/Shop/Order.php @@ -13,7 +13,7 @@ class Order extends Model */ public function Customer() { - return $this->belongsTo('App\Models\Shop\Customer'); + return $this->belongsTo(Customer::class); } /** @@ -21,6 +21,6 @@ class Order extends Model */ public function Payments() { - return $this->hasMany('App\Models\Shop\OrderPayment'); + return $this->hasMany(OrderPayment::class); } } diff --git a/app/Models/Shop/OrderPayment.php b/app/Models/Shop/OrderPayment.php index ed009fac..12adcfe9 100644 --- a/app/Models/Shop/OrderPayment.php +++ b/app/Models/Shop/OrderPayment.php @@ -13,6 +13,6 @@ class OrderPayment extends Model */ public function Order() { - return $this->belongsTo('App\Models\Shop\Order'); + return $this->belongsTo(Order::class); } } diff --git a/app/Models/Shop/Package.php b/app/Models/Shop/Package.php index bf2d6429..f813f739 100644 --- a/app/Models/Shop/Package.php +++ b/app/Models/Shop/Package.php @@ -11,16 +11,16 @@ class Package extends Model public function article_family() { - return $this->belongsTo('App\Models\Shop\ArticleNature'); + return $this->belongsTo(ArticleNature::class); } public function unities() { - return $this->hasMany('App\Models\Shop\Unity'); + return $this->hasMany(Unity::class); } public function scopeByArticleNature($query, $id) { - return $query->where('article_family_id', $id); + return $query->where($this->table . '.article_family_id', $id); } } diff --git a/app/Models/Shop/Price.php b/app/Models/Shop/Price.php index 7476c1ea..d06ecf1e 100644 --- a/app/Models/Shop/Price.php +++ b/app/Models/Shop/Price.php @@ -14,21 +14,21 @@ class Price extends Model public function article() { - return $this->belongsTo('App\Models\Shop\Article'); + return $this->belongsTo(Article::class); } public function article_family() { - return $this->belongsTo('App\Models\Shop\ArticleNature'); + return $this->belongsTo(ArticleNature::class); } public function scopeByArticle($query, $id) { - return $query->where('article_id', $id); + return $query->where($this->table . '.article_id', $id); } public function scopeByArticleNature($query, $id) { - return $query->where('article_family_id', $id); + return $query->where($this->table . '.article_family_id', $id); } } diff --git a/app/Models/Shop/PriceGenericCategory.php b/app/Models/Shop/PriceGenericCategory.php index dcb3c501..7b90ef90 100644 --- a/app/Models/Shop/PriceGenericCategory.php +++ b/app/Models/Shop/PriceGenericCategory.php @@ -11,11 +11,11 @@ class PriceGenericCategory extends Model public function article_family() { - return $this->belongsTo('App\Models\Shop\ArticleNature'); + return $this->belongsTo(ArticleNature::class); } public function price_generics() { - return $this->hasMany('App\Models\Shop\PriceGeneric', 'category_id'); + return $this->hasMany(PriceGeneric::class, 'category_id'); } } diff --git a/app/Models/Shop/PriceList.php b/app/Models/Shop/PriceList.php index 7b45de17..83619f0c 100644 --- a/app/Models/Shop/PriceList.php +++ b/app/Models/Shop/PriceList.php @@ -16,31 +16,31 @@ class PriceList extends Model public function tariff() { - return $this->belongsTo('App\Models\Shop\Tariff'); + return $this->belongsTo(Tariff::class); } public function sale_channel() { - return $this->belongsTo('App\Models\Shop\SaleChannel'); + return $this->belongsTo(SaleChannel::class); } public function price_list_values() { - return $this->hasMany('App\Models\Shop\PriceListValue'); + return $this->hasMany(PriceListValue::class); } public function scopeByTariff($query, $id) { - return $query->where('tariff_id', $id); + return $query->where($this->table . '.tariff_id', $id); } public function scopeBySaleChannel($query, $id) { - return $query->where('sale_channel_id', $id); + return $query->where($this->table . '.sale_channel_id', $id); } public function scopeByStatus($query, $id) { - return $query->where('status_id', $id); + return $query->where($this->table . '.status_id', $id); } } diff --git a/app/Models/Shop/PriceListValue.php b/app/Models/Shop/PriceListValue.php index 24ea4bad..4dc520e9 100644 --- a/app/Models/Shop/PriceListValue.php +++ b/app/Models/Shop/PriceListValue.php @@ -17,16 +17,16 @@ class PriceListValue extends Model public function price_list() { - return $this->belongsTo('App\Models\Shop\PriceList'); + return $this->belongsTo(PriceList::class); } public function scopeByPriceList($query, $id) { - return $query->where('price_list_id', $id); + return $query->where($this->table . '.price_list_id', $id); } public function scopeByQuantity($query, $quantity) { - return $query->orderBy('quantity', 'desc')->where('quantity', '<', $quantity)->first(); + return $query->orderBy('quantity', 'desc')->where($this->table . '.quantity', '<', $quantity)->first(); } } diff --git a/app/Models/Shop/Shelve.php b/app/Models/Shop/Shelve.php index 06e9f299..03c3e3dc 100644 --- a/app/Models/Shop/Shelve.php +++ b/app/Models/Shop/Shelve.php @@ -5,25 +5,25 @@ namespace App\Models\Shop; use Illuminate\Database\Eloquent\Model; use Staudenmeir\EloquentHasManyDeep\HasRelationships; -class ArticleNature extends Model +class Shelve extends Model { use HasRelationships; protected $guarded = ['id']; - protected $table = 'shop_article_families'; + protected $table = 'shop_shelves'; public function articles() { - return $this->hasMany('App\Models\Shop\Article'); + return $this->hasMany(Article::class); } public function prices() { - return $this->hasMany('App\Models\Shop\Price'); + return $this->hasMany(Price::class); } public function packages() { - return $this->hasMany('App\Models\Shop\Package'); + return $this->hasMany(Package::class); } } diff --git a/app/Models/Shop/Tag.php b/app/Models/Shop/Tag.php index 9d4aec11..affeb8fd 100644 --- a/app/Models/Shop/Tag.php +++ b/app/Models/Shop/Tag.php @@ -19,27 +19,27 @@ class Tag extends Model public function articles() { - return $this->morphedByMany('App\Models\Shop\Article','taggable'); + return $this->morphedByMany(Article::class,'taggable'); } public function varieties() { - return $this->morphedByMany('App\Models\Botanic\Variety','taggable'); + return $this->morphedByMany(\App\Models\Botanic\Variety::class,'taggable'); } public function species() { - return $this->morphedByMany('App\Models\Botanic\Specie','taggable'); + return $this->morphedByMany(\App\Models\Botanic\Specie::class,'taggable'); } public function group() { - return $this->hasOne('App\Models\Shop\TagGroup', 'id', 'tag_group_id'); + return $this->hasOne(TagGroup::class, 'id', 'tag_group_id'); } public function scopeByGroup($query, $id) { - return $query->where('tag_group_id', $id); + return $query->where($this->table . '.tag_group_id', $id); } public function getNameAttribute($value) diff --git a/app/Models/Shop/TagGroup.php b/app/Models/Shop/TagGroup.php index 06444720..596c3c0a 100644 --- a/app/Models/Shop/TagGroup.php +++ b/app/Models/Shop/TagGroup.php @@ -12,11 +12,11 @@ class TagGroup extends Model public function tags() { - return $this->hasMany('App\Models\Shop\Tag'); + return $this->hasMany(Tag::class); } public function article_family() { - return $this->belongsTo('App\Models\Shop\ArticleNature'); + return $this->belongsTo(ArticleNature::class); } } diff --git a/app/Models/Shop/Tariff.php b/app/Models/Shop/Tariff.php index 19292619..d0705130 100644 --- a/app/Models/Shop/Tariff.php +++ b/app/Models/Shop/Tariff.php @@ -17,17 +17,17 @@ class Tariff extends Model public function sale_channel() { - return $this->belongsTo('App\Models\Shop\SaleChannel'); + return $this->belongsTo(SaleChannel::class); } public function tariff_unity() { - return $this->belongsTo('App\Models\Shop\TariffUnity'); + return $this->belongsTo(TariffUnity::class); } public function price_lists() { - return $this->hasMany('App\Models\Shop\PriceList'); + return $this->hasMany(PriceList::class); } public function scopeBySaleChanel($query, $id) diff --git a/app/Models/Shop/TariffUnity.php b/app/Models/Shop/TariffUnity.php index 93ade489..38ddc57a 100644 --- a/app/Models/Shop/TariffUnity.php +++ b/app/Models/Shop/TariffUnity.php @@ -11,6 +11,6 @@ class TariffUnity extends Model public function tariffs() { - return $this->hasMany('App\Models\Shop\Tariff'); + return $this->hasMany(Tariff::class); } } diff --git a/app/Models/Shop/Tax.php b/app/Models/Shop/Tax.php index 6df7755e..8715945a 100644 --- a/app/Models/Shop/Tax.php +++ b/app/Models/Shop/Tax.php @@ -11,6 +11,6 @@ class Tax extends Model public function price() { - return $this->hasMany('App\Models\Shop\ArticlePrice', 'id', 'tax_id'); + return $this->hasMany(ArticlePrice::class, 'id', 'tax_id'); } } diff --git a/app/Models/Shop/Unity.php b/app/Models/Shop/Unity.php index 543806b5..81d18c96 100644 --- a/app/Models/Shop/Unity.php +++ b/app/Models/Shop/Unity.php @@ -16,34 +16,25 @@ class Unity extends Model public function package() { - return $this->belongsTo('App\Models\Shop\Package'); + return $this->belongsTo(Package::class); } public function article_family() { - return $this->belongsToThrough('App\Models\Shop\ArticleNature', 'App\Models\Shop\Package', null, '', ['App\Models\Shop\ArticleNature' => 'article_family_id', 'App\Models\Shop\Package' => 'package_id']); + return $this->belongsToThrough(ArticleNature::class, Package::class, null, '', ['App\Models\Shop\ArticleNature' => 'article_family_id', 'App\Models\Shop\Package' => 'package_id']); } public function scopeByPackage($query, $id) { - return $query->where('package_id', $id); + return $query->where($this->table . '.package_id', $id); } public function scopeByArticleNature($query, $id) { - return $query->whereHas( - 'package', function ($query) use ($id) { + return $query->whereHas('package', function ($query) use ($id) { $query->byArticleNature($id); } ); } - public function scopeActive($query, $active = 1) - { - return $query->whereHas( - 'third_party', function ($query) use ($active) { - $query->active($active); - } - ); - } } diff --git a/app/Models/Shop/Variation.php b/app/Models/Shop/Variation.php index 34145391..645c3016 100644 --- a/app/Models/Shop/Variation.php +++ b/app/Models/Shop/Variation.php @@ -14,11 +14,11 @@ class Variation extends Model public function package() { - return $this->belongsTo('App\Models\Shop\Package'); + return $this->belongsTo(Package::class); } public function unity() { - return $this->belongsTo('App\Models\Shop\Unity'); + return $this->belongsTo(Unity::class); } }