$g, 'user_id' => $user->id])->delete(); } return false; } //单商品默认反向增删 $favorite = self::get(['goods_id' => $goods_id, 'user_id' => $user->id]); if ($favorite) { $favorite->delete(); return false; }else{ self::create([ 'user_id' => $user->id, 'goods_id' => $goods_id ]); return true; } } public static function getGoodsList() { $user = User::info(); // 商品物理删除的,直接删掉 self::whereNotExists(function ($query) { $goodsTableName = (new Goods())->getQuery()->getTable(); $tableName = (new self())->getQuery()->getTable(); $query = $query->table($goodsTableName)->where($goodsTableName . '.id=' . $tableName . '.goods_id'); return $query; })->where([ 'user_id' => $user->id ])->delete(); $favoriteData = self::with(['goods' => function ($query) { $query->removeOption('soft_delete'); }])->where([ 'user_id' => $user->id ])->order('createtime', 'DESC')->paginate(10); return $favoriteData; } public function goods() { return $this->belongsTo(Goods::class, 'goods_id', 'id'); } }