refactor, better class namespace intergration

This commit is contained in:
Ludovic CANDELLIER
2021-10-04 14:09:51 +02:00
parent a7f661ab10
commit c150be2c3e
26 changed files with 68 additions and 78 deletions

View File

@@ -6,7 +6,6 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Image\Manipulations; use Spatie\Image\Manipulations;
use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media; use Spatie\MediaLibrary\MediaCollections\Models\Media;
@@ -27,7 +26,7 @@ class Article extends Model implements HasMedia
public function article_nature() public function article_nature()
{ {
return $this->belongsTo('App\Models\Shop\ArticleNature'); return $this->belongsTo(ArticleNature::class);
} }
public function images() public function images()
@@ -42,12 +41,12 @@ class Article extends Model implements HasMedia
public function invoiceItems() public function invoiceItems()
{ {
return $this->hasMany('App\Models\Shop\InvoiceItem'); return $this->hasMany(InvoiceItem::class);
} }
public function prices() public function prices()
{ {
return $this->hasMany('App\Models\Shop\Price'); return $this->hasMany(Price::class);
} }
public function product() public function product()
@@ -57,7 +56,7 @@ class Article extends Model implements HasMedia
public function tags() public function tags()
{ {
return $this->morphToMany('App\Models\Shop\Tag', 'taggable'); return $this->morphToMany(Tag::class, 'taggable');
} }
public function scopeByArticle($query, $id) public function scopeByArticle($query, $id)

View File

@@ -17,6 +17,6 @@ class ArticleNature extends Model
public function articles() public function articles()
{ {
return $this->hasMany('App\Models\Shop\Article'); return $this->hasMany(Article::class);
} }
} }

View File

@@ -14,12 +14,12 @@ class ArticlePrice extends Model
public function price() public function price()
{ {
return $this->hasOne('App\Models\Price'); return $this->hasOne(Price::class);
} }
public function article_family() public function article_family()
{ {
return $this->belongsTo('App\Models\ArticleNature'); return $this->belongsTo(ArticleNature::class);
} }
public function scopeByQuantity($query, $quantity) public function scopeByQuantity($query, $quantity)
@@ -29,6 +29,6 @@ class ArticlePrice extends Model
public function scopeByFamily($query, $id) public function scopeByFamily($query, $id)
{ {
return $query->where('article_family_value_id', $id); return $query->where($this->table . '.article_family_value_id', $id);
} }
} }

View File

@@ -22,12 +22,12 @@ class Category extends Model
public function Articles() public function Articles()
{ {
return $this->morphedByMany('App\Models\Shop\Article', 'categorizable'); return $this->morphedByMany(Article::class, 'categorizable');
} }
public function Shelves() public function Shelves()
{ {
return $this->morphedByMany('App\Models\Shop\Category', 'categorizable'); return $this->morphedByMany(Category::class, 'categorizable');
} }
public function CategoryTree() public function CategoryTree()

View File

@@ -11,12 +11,12 @@ class Customer extends Model
public function Invoices() public function Invoices()
{ {
return $this->hasMany('App\Models\Shop\Invoice'); return $this->hasMany(Invoice::class);
} }
public function Orders() public function Orders()
{ {
return $this->hasMany('App\Models\Shop\Order'); return $this->hasMany(Order::class);
} }
public function User() public function User()

View File

@@ -10,11 +10,11 @@ class CustomerAddress extends Model
public function Customer() public function Customer()
{ {
return $this->belongsTo('App\Models\Shop\Customer'); return $this->belongsTo(Customer::class);
} }
public function Orders() public function Orders()
{ {
return $this->hasMany('App\Models\Shop\Order'); return $this->hasMany(Order::class);
} }
} }

View File

@@ -10,10 +10,10 @@ class DistributionChannel extends Model
use HasRelationships; use HasRelationships;
protected $guarded = ['id']; protected $guarded = ['id'];
protected $table = 'shop_article_families'; protected $table = 'shop_distribution_channel';
public function tariff_generics() public function tariff_generics()
{ {
return $this->hasMany('App\Models\Shop\TariffGeneric'); return $this->hasMany(TariffGeneric::class);
} }
} }

View File

@@ -13,7 +13,7 @@ class Invoice extends Model
*/ */
public function InvoiceItems() 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() public function Customer()
{ {
return $this->belongsTo('App\Models\Shop\Customer'); return $this->belongsTo(Customer::class);
} }
} }

View File

@@ -13,7 +13,7 @@ class InvoiceItem extends Model
*/ */
public function Product() 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() public function Invoice()
{ {
return $this->belongsTo('App\Models\Shop\Invoice'); return $this->belongsTo(Invoice::class);
} }
} }

View File

@@ -15,6 +15,6 @@ class Merchandise extends Model
public function Articles() public function Articles()
{ {
return $this->morphMany('App\Models\Shop\Article', 'product'); return $this->morphMany(Article::class, 'product');
} }
} }

View File

@@ -14,16 +14,16 @@ class Offer extends Model
public function article() public function article()
{ {
return $this->belongsTo('App\Models\Shop\Article'); return $this->belongsTo(Article::class);
} }
public function variation() public function variation()
{ {
return $this->belongsTo('App\Models\Shop\Variation'); return $this->belongsTo(Variation::class);
} }
public function tariff() public function tariff()
{ {
return $this->belongsTo('App\Models\Shop\Tariff'); return $this->belongsTo(Tariff::class);
} }
} }

View File

@@ -13,7 +13,7 @@ class Order extends Model
*/ */
public function Customer() 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() public function Payments()
{ {
return $this->hasMany('App\Models\Shop\OrderPayment'); return $this->hasMany(OrderPayment::class);
} }
} }

View File

@@ -13,6 +13,6 @@ class OrderPayment extends Model
*/ */
public function Order() public function Order()
{ {
return $this->belongsTo('App\Models\Shop\Order'); return $this->belongsTo(Order::class);
} }
} }

View File

@@ -11,16 +11,16 @@ class Package extends Model
public function article_family() public function article_family()
{ {
return $this->belongsTo('App\Models\Shop\ArticleNature'); return $this->belongsTo(ArticleNature::class);
} }
public function unities() public function unities()
{ {
return $this->hasMany('App\Models\Shop\Unity'); return $this->hasMany(Unity::class);
} }
public function scopeByArticleNature($query, $id) public function scopeByArticleNature($query, $id)
{ {
return $query->where('article_family_id', $id); return $query->where($this->table . '.article_family_id', $id);
} }
} }

View File

@@ -14,21 +14,21 @@ class Price extends Model
public function article() public function article()
{ {
return $this->belongsTo('App\Models\Shop\Article'); return $this->belongsTo(Article::class);
} }
public function article_family() public function article_family()
{ {
return $this->belongsTo('App\Models\Shop\ArticleNature'); return $this->belongsTo(ArticleNature::class);
} }
public function scopeByArticle($query, $id) public function scopeByArticle($query, $id)
{ {
return $query->where('article_id', $id); return $query->where($this->table . '.article_id', $id);
} }
public function scopeByArticleNature($query, $id) public function scopeByArticleNature($query, $id)
{ {
return $query->where('article_family_id', $id); return $query->where($this->table . '.article_family_id', $id);
} }
} }

View File

@@ -11,11 +11,11 @@ class PriceGenericCategory extends Model
public function article_family() public function article_family()
{ {
return $this->belongsTo('App\Models\Shop\ArticleNature'); return $this->belongsTo(ArticleNature::class);
} }
public function price_generics() public function price_generics()
{ {
return $this->hasMany('App\Models\Shop\PriceGeneric', 'category_id'); return $this->hasMany(PriceGeneric::class, 'category_id');
} }
} }

View File

@@ -16,31 +16,31 @@ class PriceList extends Model
public function tariff() public function tariff()
{ {
return $this->belongsTo('App\Models\Shop\Tariff'); return $this->belongsTo(Tariff::class);
} }
public function sale_channel() public function sale_channel()
{ {
return $this->belongsTo('App\Models\Shop\SaleChannel'); return $this->belongsTo(SaleChannel::class);
} }
public function price_list_values() public function price_list_values()
{ {
return $this->hasMany('App\Models\Shop\PriceListValue'); return $this->hasMany(PriceListValue::class);
} }
public function scopeByTariff($query, $id) public function scopeByTariff($query, $id)
{ {
return $query->where('tariff_id', $id); return $query->where($this->table . '.tariff_id', $id);
} }
public function scopeBySaleChannel($query, $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) public function scopeByStatus($query, $id)
{ {
return $query->where('status_id', $id); return $query->where($this->table . '.status_id', $id);
} }
} }

View File

@@ -17,16 +17,16 @@ class PriceListValue extends Model
public function price_list() public function price_list()
{ {
return $this->belongsTo('App\Models\Shop\PriceList'); return $this->belongsTo(PriceList::class);
} }
public function scopeByPriceList($query, $id) 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) 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();
} }
} }

View File

@@ -5,25 +5,25 @@ namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Staudenmeir\EloquentHasManyDeep\HasRelationships; use Staudenmeir\EloquentHasManyDeep\HasRelationships;
class ArticleNature extends Model class Shelve extends Model
{ {
use HasRelationships; use HasRelationships;
protected $guarded = ['id']; protected $guarded = ['id'];
protected $table = 'shop_article_families'; protected $table = 'shop_shelves';
public function articles() public function articles()
{ {
return $this->hasMany('App\Models\Shop\Article'); return $this->hasMany(Article::class);
} }
public function prices() public function prices()
{ {
return $this->hasMany('App\Models\Shop\Price'); return $this->hasMany(Price::class);
} }
public function packages() public function packages()
{ {
return $this->hasMany('App\Models\Shop\Package'); return $this->hasMany(Package::class);
} }
} }

View File

@@ -19,27 +19,27 @@ class Tag extends Model
public function articles() public function articles()
{ {
return $this->morphedByMany('App\Models\Shop\Article','taggable'); return $this->morphedByMany(Article::class,'taggable');
} }
public function varieties() public function varieties()
{ {
return $this->morphedByMany('App\Models\Botanic\Variety','taggable'); return $this->morphedByMany(\App\Models\Botanic\Variety::class,'taggable');
} }
public function species() public function species()
{ {
return $this->morphedByMany('App\Models\Botanic\Specie','taggable'); return $this->morphedByMany(\App\Models\Botanic\Specie::class,'taggable');
} }
public function group() 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) 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) public function getNameAttribute($value)

View File

@@ -12,11 +12,11 @@ class TagGroup extends Model
public function tags() public function tags()
{ {
return $this->hasMany('App\Models\Shop\Tag'); return $this->hasMany(Tag::class);
} }
public function article_family() public function article_family()
{ {
return $this->belongsTo('App\Models\Shop\ArticleNature'); return $this->belongsTo(ArticleNature::class);
} }
} }

View File

@@ -17,17 +17,17 @@ class Tariff extends Model
public function sale_channel() public function sale_channel()
{ {
return $this->belongsTo('App\Models\Shop\SaleChannel'); return $this->belongsTo(SaleChannel::class);
} }
public function tariff_unity() public function tariff_unity()
{ {
return $this->belongsTo('App\Models\Shop\TariffUnity'); return $this->belongsTo(TariffUnity::class);
} }
public function price_lists() public function price_lists()
{ {
return $this->hasMany('App\Models\Shop\PriceList'); return $this->hasMany(PriceList::class);
} }
public function scopeBySaleChanel($query, $id) public function scopeBySaleChanel($query, $id)

View File

@@ -11,6 +11,6 @@ class TariffUnity extends Model
public function tariffs() public function tariffs()
{ {
return $this->hasMany('App\Models\Shop\Tariff'); return $this->hasMany(Tariff::class);
} }
} }

View File

@@ -11,6 +11,6 @@ class Tax extends Model
public function price() public function price()
{ {
return $this->hasMany('App\Models\Shop\ArticlePrice', 'id', 'tax_id'); return $this->hasMany(ArticlePrice::class, 'id', 'tax_id');
} }
} }

View File

@@ -16,34 +16,25 @@ class Unity extends Model
public function package() public function package()
{ {
return $this->belongsTo('App\Models\Shop\Package'); return $this->belongsTo(Package::class);
} }
public function article_family() 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) public function scopeByPackage($query, $id)
{ {
return $query->where('package_id', $id); return $query->where($this->table . '.package_id', $id);
} }
public function scopeByArticleNature($query, $id) public function scopeByArticleNature($query, $id)
{ {
return $query->whereHas( return $query->whereHas('package', function ($query) use ($id) {
'package', function ($query) use ($id) {
$query->byArticleNature($id); $query->byArticleNature($id);
} }
); );
} }
public function scopeActive($query, $active = 1)
{
return $query->whereHas(
'third_party', function ($query) use ($active) {
$query->active($active);
}
);
}
} }

View File

@@ -14,11 +14,11 @@ class Variation extends Model
public function package() public function package()
{ {
return $this->belongsTo('App\Models\Shop\Package'); return $this->belongsTo(Package::class);
} }
public function unity() public function unity()
{ {
return $this->belongsTo('App\Models\Shop\Unity'); return $this->belongsTo(Unity::class);
} }
} }