[WIP] Refactor models to better lisibility and speed
This commit is contained in:
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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user