Add method to get offers by articles with siblings, enhance display
This commit is contained in:
@@ -50,6 +50,11 @@ class Article extends Model implements HasMedia
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function siblings()
|
||||
{
|
||||
return $this->hasMany(Article::class, 'name', 'name');
|
||||
}
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
|
||||
@@ -4,11 +4,12 @@ namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use Znck\Eloquent\Traits\BelongsToThrough;
|
||||
use App\Traits\Model\HasComments;
|
||||
|
||||
class Offer extends Model
|
||||
{
|
||||
use HasComments;
|
||||
use BelongsToThrough, HasComments;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_offers';
|
||||
@@ -18,6 +19,14 @@ class Offer extends Model
|
||||
return $this->belongsTo(Article::class);
|
||||
}
|
||||
|
||||
public function article_nature()
|
||||
{
|
||||
return $this->belongsToThrough(ArticleNature::class, Article::class, null, '', [
|
||||
'App\Models\Shop\Article' => 'article_id',
|
||||
'App\Models\Shop\ArticleNature' => 'article_nature_id',
|
||||
]);
|
||||
}
|
||||
|
||||
public function tariff()
|
||||
{
|
||||
return $this->belongsTo(Tariff::class);
|
||||
@@ -63,6 +72,11 @@ class Offer extends Model
|
||||
return $query->where($this->table . '.article_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByArticles($query, $ids)
|
||||
{
|
||||
return $query->whereIn($this->table . '.article_id', $ids);
|
||||
}
|
||||
|
||||
public function scopeByOffer($query, $id)
|
||||
{
|
||||
return $query->where($this->table . '.id', $id);
|
||||
|
||||
Reference in New Issue
Block a user