Files
opensem/app/Models/Shop/Article.php
Ludovic CANDELLIER 71e27ce9c3 Fixes on new model
2020-07-26 23:17:49 +02:00

54 lines
1.3 KiB
PHP

<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia\HasMedia;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
use Rinvex\Categories\Traits\Categorizable;
use Rinvex\Tags\Traits\Taggable;
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
class Article extends Model implements HasMedia
{
use Categorizable, Taggable, HasMediaTrait, EloquentJoin;
protected $guarded = ['id'];
protected $table = 'shop_articles';
public function article_family()
{
return $this->belongsTo('App\Models\Shop\ArticleFamily');
}
public function attributes()
{
return $this->hasMany('App\Models\Shop\ArticleAttribute');
}
public function prices()
{
return $this->hasManyThrough('App\Models\Shop\ArticlePrice','App\Models\Shop\ArticleAttribute');
}
public function inventories()
{
return $this->hasMany('App\Models\Shop\Inventory');
}
public function invoiceItems()
{
return $this->hasMany('App\Models\Shop\InvoiceItem');
}
public function product()
{
return $this->belongsTo($this->model, 'model_id');
}
public function scopeByArticle($query, $id)
{
return $query->where('shop_articles.id',$id);
}
}