Skip to content

Commit

Permalink
Saved a couple of queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ok200paul committed Sep 30, 2024
1 parent 33b787a commit b564e9c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/Services/VoucherService.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ public static function collateVoucherAggregates(Voucher $voucher): void
$voucher->voucher_short_code = null;
}

$voucher->num_voucher_redemptions = VoucherRedemption::where('voucher_id', $voucher->id)->count();
$voucher->last_redemption_at = VoucherRedemption::where('voucher_id')->max('created_at');
if($voucher->voucher_value_remaining != $voucher->voucher_value_original)
{
$voucher->num_voucher_redemptions = VoucherRedemption::where('voucher_id', $voucher->id)->count();
$voucher->last_redemption_at = VoucherRedemption::where('voucher_id')->max('created_at');
}

$voucher->saveQuietly();
}
Expand Down

0 comments on commit b564e9c

Please sign in to comment.