[WIP] Refactor architecture, models

This commit is contained in:
Ludovic CANDELLIER
2020-04-22 01:26:03 +02:00
parent e370174f94
commit a18d30b65c
39 changed files with 446 additions and 266 deletions

View File

@@ -5,12 +5,20 @@ namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Rinvex\Categories\Traits\Categorizable;
use Conner\Tagging\Taggable;
class Product extends Model
class Article extends Model
{
use Categorizable;
use Taggable;
protected $guarded = ['id'];
protected $table = 'shop_products';
protected $table = 'shop_articles';
public function Family()
{
return $this->belongsTo('App\Models\Shop\Family');
}
public function Inventories()
{
@@ -19,17 +27,17 @@ class Product extends Model
public function Prices()
{
return $this->hasMany('App\Models\Shop\ProductPrice');
return $this->hasMany('App\Models\Shop\ArticlePrice');
}
public function ProductAttributes()
{
return $this->hasMany('App\Models\Shop\ProductAttribute');
return $this->hasMany('App\Models\Shop\ArticleAttribute');
}
public function Categories()
{
return $this->hasMany('App\Models\Shop\CategoryProduct');
return $this->hasMany('App\Models\Shop\ArticleCategory');
}
public function InvoiceItems()

View File

@@ -4,15 +4,15 @@ namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class ProductAttribute extends Model
class ArticleAttribute extends Model
{
protected $guarded = ['id'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function Product()
public function Article()
{
return $this->belongsTo('App\Models\Shop\Product');
return $this->belongsTo('App\Models\Shop\Article');
}
}

View File

@@ -0,0 +1,31 @@
<?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);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class ArticleFamily extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_article_families';
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function Articles()
{
return $this->hasMany('App\Models\Shop\Article');
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class ArticlePrice extends Model
{
protected $guarded = ['id'];
public function Article()
{
return $this->belongsTo('App\Models\Shop\Article');
}
public function ArticleAttribute()
{
return $this->belongsTo('App\Models\Shop\ArticleAttribute');
}
public function scopeByArticle($query, $id)
{
return $query->where('article_id', $id);
}
}

View File

@@ -5,11 +5,12 @@ namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Rinvex\Categories\Traits\Categorizable;
use Conner\Tagging\Taggable;
class Section extends Model
class Category extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_sections';
protected $table = 'shop_categories';
public function Category()
{

View File

@@ -1,26 +0,0 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class ProductPrice extends Model
{
protected $guarded = ['id'];
public function Product()
{
return $this->belongsTo('App\Models\Shop\Product');
}
public function ProductAttribute()
{
return $this->belongsTo('App\Models\Shop\ProductAttribute');
}
public function scopeByProduct($query, $id)
{
return $query->where('product_id', $id);
}
}

View File

@@ -1,31 +0,0 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class ProductSection extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_product_sections';
public function Product()
{
return $this->belongsTo('App\Models\Shop\Product');
}
public function Section()
{
return $this->belongsTo('App\Models\Shop\Product');
}
public function scopeByProduct($query, $id)
{
return $query->where('product_id', $id);
}
public function scopeBySection($query, $id)
{
return $query->where('section_id', $id);
}
}