false, ]; /** * @var array */ protected $fillable = [ 'key', 'name', 'is_show', ]; /** * @var array */ protected $casts = [ 'is_show' => 'bool', ]; /** * 属于此分区的商品关系 * * @return void */ public function partSkus() { return $this->hasMany(ProductPartSku::class, 'part_id')->orderBy('sort', 'desc'); } public function skus() { return $this->belongsToMany(ProductSku::class, ProductPartSku::class, 'part_id', 'sku_id')->withTimestamps(); } public function spus() { return $this->belongsToMany(ProductSpu::class, ProductPartSpu::class, 'part_id', 'spu_id')->withTimestamps(); } /** * 此分区购买赠送的券关系 */ public function coupons() { return $this->hasMany(ProductPartCoupon::class, 'part_id'); } /** * 返回实际关联的券 * @return queryBuilder */ public function getCoupons() { return Coupon::whereIn('id', $this->coupons->pluck('coupon_id')->toArray()); } }