我在用户模型和钱包模型之间存在多对多关系:
Wallet.php
:
public function users()
{
return $this->belongsToMany(User::class);
}
并且User.php
:
public function wallets()
{
return $this->belongsToMany(Wallet::class);
}
我想像这样获取单个用户的钱包列表:
@forelse($user->wallets as $wallet)
<tr>
<td>{{ $wallet->id }}</td>
</tr>
@empty
<td colspan="5" class="text-center">No wallet exist</td>
@endforelse
但是我以某种方式收到此错误:
SQLSTATE [42S22]:找不到列:1054 '字段列表'中的未知列'user_wallet.user_usr_id'(SQL:选择. *
wallets
,.user_wallet
asuser_usr_id
,pivot_user_usr_id
.as from inner join on . = . where . = 373)user_wallet
wallet_id
pivot_wallet_id
wallets
user_wallet
wallets
id
user_wallet
wallet_id
user_wallet
user_usr_id
但是,此用户 ID 中的钱包已经存在于user_wallet
表中:
那么这里出了什么问题?我该如何解决这个问题?
我真的很感激你们关于这个的任何想法或建议......
提前致谢。