JsonArray::class, 'sell_price' => Price::class, 'market_price' => Price::class, 'cost_price' => Price::class, 'vip_price' => Price::class, 'attrs' => JsonArray::class, 'specs' => 'json', 'release_at' => 'datetime', ]; /** * @var array */ protected $fillable = [ 'spu_id', 'name', 'subtitle', 'category_id', 'codcovere', 'images', 'sell_price', 'market_price', 'cost_price', 'vip_price', 'media', 'weight', 'attrs', 'specs', 'stock', 'sales', 'release_at', ]; /** * 仅查询已上架的商品 * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function scopeIsRelease($query) { return $query->whereNotNull('release_at'); } /** * 此商品所属的分类 */ public function category() { return $this->belongsTo(ProductCategory::class, 'category_id'); } /** * 此商品所属的分区 */ public function parts() { return $this->belongsToMany(ProductPart::class, ProductPartSku::class, 'sku_id', 'part_id'); } }