Add categories for generic prices
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
18
app/Models/Shop/PriceGenericCategory.php
Normal file
18
app/Models/Shop/PriceGenericCategory.php
Normal 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');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user