54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Shop;
|
|
|
|
use App\Traits\Model\Imageable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Kirschbaum\PowerJoins\PowerJoins;
|
|
use Rinvex\Tags\Traits\Taggable;
|
|
use Spatie\MediaLibrary\HasMedia;
|
|
use Venturecraft\Revisionable\RevisionableTrait;
|
|
use Wildside\Userstamps\Userstamps;
|
|
|
|
class Merchandise extends Model implements HasMedia
|
|
{
|
|
use Imageable, PowerJoins, RevisionableTrait, SoftDeletes, Taggable, UserStamps;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $table = 'shop_merchandises';
|
|
|
|
protected $revisionEnabled = true;
|
|
|
|
protected $keepRevisionOf = [
|
|
'producer_id',
|
|
'name',
|
|
'description',
|
|
'plus',
|
|
];
|
|
|
|
public function Articles(): MorphMany
|
|
{
|
|
return $this->morphMany(Article::class, 'product');
|
|
}
|
|
|
|
public function Producer(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Producer::class);
|
|
}
|
|
|
|
public function tags(): MorphToMany
|
|
{
|
|
return $this->morphToMany(Tag::class, 'taggable');
|
|
}
|
|
|
|
public function scopeByProducer($query, $producerId)
|
|
{
|
|
return $query->where('producer_id', $producerId);
|
|
}
|
|
}
|