fix: sum an offer's reserved merchants in PHP, no raw SQL on the count column

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-31 11:05:15 +01:00
parent 7303817911
commit 4c8a002718
1 changed files with 1 additions and 2 deletions

View File

@ -13,7 +13,6 @@ use App\Models\TradeOffer;
use App\Models\TradeRoute;
use App\Models\Village;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\DB;
/**
* The market of one village (architecture.md, "Market"). Merchants under way are
@ -59,7 +58,7 @@ final class Market
->where(fn ($q) => $q->where('origin_id', $id)->where('type', Movement::TRADE))
->orWhere(fn ($q) => $q->where('target_id', $id)->where('type', Movement::TRADE_RETURN)))
->sum('merchants');
$reserved = (int) TradeOffer::where('village_id', $id)->sum(DB::raw('count * merchants'));
$reserved = TradeOffer::where('village_id', $id)->get(['count', 'merchants'])->sum(fn (TradeOffer $o) => $o->count * $o->merchants);
return $moving + $reserved;
}