57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Peidikeji\Goods\Models;
|
|
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Peidikeji\Goods\Filters\GoodsFilter;
|
|
|
|
class Goods extends Model
|
|
{
|
|
use SoftDeletes;
|
|
use Filterable;
|
|
|
|
protected $table = 'goods';
|
|
|
|
protected $fillable = ['attr', 'category_id', 'type_id', 'brand_id', 'content', 'cover_image', 'deleted_at', 'description', 'goods_sn', 'images', 'name', 'on_sale', 'part', 'price', 'discount_price', 'sold_count', 'spec', 'stock'];
|
|
|
|
protected $casts = [
|
|
'attr' => 'array',
|
|
'spec' => 'array',
|
|
'part' => 'array',
|
|
'content' => 'array',
|
|
'images' => 'array',
|
|
];
|
|
|
|
public function modelFilter()
|
|
{
|
|
return GoodsFilter::class;
|
|
}
|
|
|
|
public function category()
|
|
{
|
|
return $this->belongsTo(GoodsCategory::class, 'category_id');
|
|
}
|
|
|
|
public function type()
|
|
{
|
|
return $this->belongsTo(GoodsType::class, 'type_id');
|
|
}
|
|
|
|
public function brand()
|
|
{
|
|
return $this->belongsTo(GoodsBrand::class, 'brand_id');
|
|
}
|
|
|
|
public function skus()
|
|
{
|
|
return $this->hasMany(GoodsSku::class, 'goods_id');
|
|
}
|
|
|
|
public function scopeSort($q)
|
|
{
|
|
return $q->orderBy('created_at', 'desc');
|
|
}
|
|
}
|