authorize('view', $customer); abort_unless((int) $customer->company_id === (int) $request->header('company'), 404); $payments = Payment::query() ->where('company_id', $customer->company_id) ->where('customer_id', $customer->id) ->whereIn('id', collect($request->validated('allocations'))->pluck('payment_id')->unique()) ->get(); foreach ($payments as $payment) { $this->authorize('update', $payment); } $this->paymentAllocationService->applyCustomerCredits( (int) $request->header('company'), $customer->id, $request->validated('allocations'), ); return response()->json(['success' => true]); } }