Add categories for generic prices

This commit is contained in:
Ludovic CANDELLIER
2020-08-31 00:44:29 +02:00
parent 3b6108b449
commit c9198de890
26 changed files with 471 additions and 242 deletions

View File

@@ -12,9 +12,14 @@ class PriceGeneric extends Model
protected $guarded = ['id'];
protected $table = 'shop_price_generics';
public function category()
{
return $this->hasOne('App\Models\Shop\PriceGenericCategory','id','category_id');
}
public function prices()
{
return $this->hasMany('App\Models\Shop\Price');
return $this->hasMany('App\Models\Shop\Price','price_id')->where('price_type','App\Models\Shop\PriceGeneric');
}
public function values()
@@ -22,9 +27,19 @@ class PriceGeneric extends Model
return $this->hasMany('App\Models\Shop\PriceGenericValue');
}
public function priceByUnit()
{
return $this->hasOne('App\Models\Shop\PriceGenericValue')->orderBy('quantity','asc');
}
public function articles()
{
return $this->hasManyThrough('App\Models\Shop\Article','App\Models\Shop\Price');
}
public function scopeByCategory($query, $id)
{
return $query->where('category_id', $id);
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class PriceGenericCategory extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_price_generic_categories';
public function price_generics()
{
return $this->hasMany('App\Models\Shop\PriceGeneric','category_id');
}
}