samedi 21 mai 2016

Trying to bulk update instead of one by one in Laravel 5.2.31

I am using the following code to check all active memberships of the user

$UserMemberships = \App\Models\User\Membership\UserMembershipModel
::where('UserID', $UserID)
->where('IsActive', true)
->get();

Then I am setting the active statue of membership to false one by one.

foreach($UserMemberships as $UserMembership) {
    $UserMembership->IsActive = false;
    $UserMembership->save();
}

Is there any way to do it in one shot?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire