public function store($reportId, AppMailer $mailer) { $report = ExpenseReport::find($reportId)->load('owner', 'users'); $input = Request::all(); if (session()->has('settlements')) { $input = session('settlements'); } $oweesAndOwed = $report->oweesAndOwed(); $owees = $oweesAndOwed["owees"]; foreach ($owees as $oweeKey => $owee) { $owed = $oweesAndOwed["owed"]; foreach ($owed as $owedKey => $owed) { if (array_key_exists("settlementowee" . $oweeKey . "owed" . $owedKey, $input)) { $settlementAmount = $input["settlementowee" . $oweeKey . "owed" . $owedKey]; Settlement::create(['owee_id' => $oweeKey, 'owed_id' => $owedKey, 'report_id' => $report->id, 'amount' => $settlementAmount]); } } } $report->updateStatus(2); $mailer->sendSettlementsDeterminedNotification($report); return redirect('settlements/' . $report->id); }