我使用以下代码检查用户的所有活动成员资格
$UserMemberships = \App\Models\User\Membership\UserMembershipModel
::where('UserID', $UserID)
->where('IsActive', true)
->get();
然后我逐个将成员资格的活动状态设置为false。
foreach($UserMemberships as $UserMembership) {
$UserMembership->IsActive = false;
$UserMembership->save();
}
有没有办法一次性完成?
答案 0 :(得分:1)
您可以直接更新记录,尝试此查询:
$UserMemberships = \App\Models\User\Membership\UserMembershipModel
::where('UserID', $UserID)
->where('IsActive', true)
->update(['IsActive' => false]);