From e5a35779f8c66c090c644afd3a966e34d3b928e9 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sun, 1 Mar 2026 15:36:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9AUserPurchase=20?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E8=A1=A5=E5=85=85=20item()=20=E5=85=B3?= =?UTF-8?q?=E8=81=94=E5=88=AB=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 婚姻系统 whereHas('item') / with('item') 需要此方法, 原模型只有 shopItem(),现在加 item() 作为别名指向同一外键。 --- app/Models/UserPurchase.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Models/UserPurchase.php b/app/Models/UserPurchase.php index f46b4d7..7c0e6ed 100644 --- a/app/Models/UserPurchase.php +++ b/app/Models/UserPurchase.php @@ -32,6 +32,14 @@ class UserPurchase extends Model return $this->belongsTo(User::class); } + /** + * 购买记录对应的商品(shopItem 别名,兼容婚姻系统调用) + */ + public function item(): BelongsTo + { + return $this->belongsTo(ShopItem::class, 'shop_item_id'); + } + /** * 购买记录对应的商品 */