[WIP] Refactor models to better lisibility and speed
This commit is contained in:
@@ -48,7 +48,7 @@ class Article extends Model implements HasMedia
|
||||
|
||||
public function prices()
|
||||
{
|
||||
return $this->hasManyThrough('App\Models\Shop\ArticlePrice','App\Models\Shop\ArticleAttribute');
|
||||
return $this->hasMany('App\Models\Shop\Price');
|
||||
}
|
||||
|
||||
public function product()
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ArticleAttribute extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_article_attributes';
|
||||
|
||||
public function article()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Article');
|
||||
}
|
||||
|
||||
public function attribute_value()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\ArticleAttributeValue', 'article_attribute_value_id');
|
||||
}
|
||||
|
||||
public function prices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\ArticlePrice');
|
||||
}
|
||||
|
||||
public function scopeByArticle($query, $id)
|
||||
{
|
||||
return $query->where('article_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByAttributeValue($query, $id)
|
||||
{
|
||||
return $query->where('attribute_value_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByFamily($query, $id)
|
||||
{
|
||||
return $query->whereHas('attribute_value', function ($query) use ($id) {
|
||||
$query->byFamily($id);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
|
||||
class ArticleAttributeFamily extends Model
|
||||
{
|
||||
use HasRelationships;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_article_attribute_families';
|
||||
|
||||
public function values()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\ArticleAttributeValue');
|
||||
}
|
||||
|
||||
public function articles()
|
||||
{
|
||||
return $this->hasManyThrough('App\Models\Shop\ArticleAttribute','App\Models\Shop\ArticleAttributeValue');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ArticleAttributeValue extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_article_attribute_values';
|
||||
|
||||
public function article_attribute_family()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\ArticleAttributeFamily');
|
||||
}
|
||||
|
||||
public function attributes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\ArticleAttribute');
|
||||
}
|
||||
|
||||
public function articles()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\ArticleAttribute')->groupBy('article_id');
|
||||
}
|
||||
|
||||
public function scopeByFamily($query, $id)
|
||||
{
|
||||
return $query->where('article_attribute_family_id', $id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ArticleCategory extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_article_categories';
|
||||
|
||||
public function article()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Article');
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Category');
|
||||
}
|
||||
|
||||
public function scopeByArticle($query, $id)
|
||||
{
|
||||
return $query->where('article_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByCategory($query, $id)
|
||||
{
|
||||
return $query->where('category_id', $id);
|
||||
}
|
||||
}
|
||||
@@ -7,46 +7,28 @@ use Znck\Eloquent\Traits\BelongsToThrough;
|
||||
|
||||
class ArticlePrice extends Model
|
||||
{
|
||||
use BelongsToThrough;
|
||||
use BelongsToThrough;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_article_prices';
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_article_prices';
|
||||
|
||||
public function article_attribute()
|
||||
public function price()
|
||||
{
|
||||
return $this->hasOne('App\Models\Price');
|
||||
}
|
||||
|
||||
public function priceFamilyValue()
|
||||
{
|
||||
return $this->belongsTo('App\Models\PriceFamilyValue');
|
||||
}
|
||||
|
||||
public function scopeByQuantity($query, $quantity)
|
||||
{
|
||||
return $query->orderBy('quantity', 'desc')->where('quantity', '<', $quantity)->first();
|
||||
}
|
||||
|
||||
public function scopeByPriceFamilyValue($query, $id)
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\ArticleAttribute');
|
||||
}
|
||||
|
||||
public function article()
|
||||
{
|
||||
return $this->belongsToThrough(
|
||||
'App\Models\Shop\Article',
|
||||
'App\Models\Shop\ArticleAttribute',
|
||||
null,
|
||||
'',
|
||||
['App\Models\Shop\Article' => 'article_id', 'App\Models\Shop\ArticleAttribute' => 'article_attribute_id']
|
||||
);
|
||||
}
|
||||
|
||||
public function scopeByArticle($query, $id)
|
||||
{
|
||||
return $query->whereHas('article', function ($query) use ($id) {
|
||||
$query->byArticle($id);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeByAttributeValue($query, $id)
|
||||
{
|
||||
return $query->whereHas('article_attribute', function ($query) use ($id) {
|
||||
$query->byAttributeValue($id);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeByFamily($query, $id)
|
||||
{
|
||||
return $query->whereHas('article_attribute', function ($query) use ($id) {
|
||||
$query->byFamily($id);
|
||||
});
|
||||
}
|
||||
|
||||
return $query->where('price_family_value_id', $id);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Znck\Eloquent\Traits\BelongsToThrough;
|
||||
|
||||
class ArticlePriceGeneric extends Model
|
||||
{
|
||||
use BelongsToThrough;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_article_price_generics';
|
||||
|
||||
public function article_prices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\ArticlePrice');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Inventory extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function InventoryPlace()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\InventoryPlace');
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class InventoryPlace extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function Inventories()
|
||||
{
|
||||
return $this->hasMany('App\Models\Inventory');
|
||||
}
|
||||
}
|
||||
40
app/Models/Shop/Price.php
Normal file
40
app/Models/Shop/Price.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
|
||||
class Price extends Model
|
||||
{
|
||||
use HasRelationships;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_prices';
|
||||
|
||||
public function article()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Article');
|
||||
}
|
||||
|
||||
public function price_family()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\PriceFamily');
|
||||
}
|
||||
|
||||
public function price()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function scopeByArticle($query, $id)
|
||||
{
|
||||
return $query->where('article_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByPriceFamily($query, $id)
|
||||
{
|
||||
return $query->where('price_family_id', $id);
|
||||
}
|
||||
|
||||
}
|
||||
30
app/Models/Shop/PriceFamily.php
Normal file
30
app/Models/Shop/PriceFamily.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
|
||||
class PriceFamily extends Model
|
||||
{
|
||||
use HasRelationships;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_price_families';
|
||||
|
||||
public function prices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\Price');
|
||||
}
|
||||
|
||||
public function values()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\PriceFamilyValue');
|
||||
}
|
||||
|
||||
public function articles()
|
||||
{
|
||||
return $this->hasManyThrough('App\Models\Shop\Article','App\Models\Shop\Price');
|
||||
}
|
||||
|
||||
}
|
||||
22
app/Models/Shop/PriceFamilyValue.php
Normal file
22
app/Models/Shop/PriceFamilyValue.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PriceFamilyValue extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_price_familiy_values';
|
||||
|
||||
public function price_family()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\PriceFamily');
|
||||
}
|
||||
|
||||
public function scopeByFamily($query, $id)
|
||||
{
|
||||
return $query->where('price_family_id');
|
||||
}
|
||||
|
||||
}
|
||||
30
app/Models/Shop/PriceGeneric.php
Normal file
30
app/Models/Shop/PriceGeneric.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Znck\Eloquent\Traits\BelongsToThrough;
|
||||
|
||||
class PriceGeneric extends Model
|
||||
{
|
||||
use BelongsToThrough;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_price_generics';
|
||||
|
||||
public function prices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\Price');
|
||||
}
|
||||
|
||||
public function values()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\PriceGenericValue');
|
||||
}
|
||||
|
||||
public function articles()
|
||||
{
|
||||
return $this->hasManyThrough('App\Models\Shop\Article','App\Models\Shop\Price');
|
||||
}
|
||||
|
||||
}
|
||||
30
app/Models/Shop/PriceGenericValue.php
Normal file
30
app/Models/Shop/PriceGenericValue.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Znck\Eloquent\Traits\BelongsToThrough;
|
||||
|
||||
class PriceGenericValue extends Model
|
||||
{
|
||||
use BelongsToThrough;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_price_generic_values';
|
||||
|
||||
public function price_generic()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\PriceGeneric');
|
||||
}
|
||||
|
||||
public function scopeByPriceGeneric($query, $id)
|
||||
{
|
||||
return $query->where('price_generic_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByQuantity($query, $quantity)
|
||||
{
|
||||
return $query->orderBy('quantity', 'desc')->where('quantity', '<', $quantity)->first();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user