From c05a0dd5982937fa6b2cbd4a5ac99e165f1e98dd Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 28 Oct 2022 10:37:58 +1100 Subject: [PATCH] restore paymentable reliably when restoring invoice with attached payment --- app/Services/Invoice/HandleRestore.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Services/Invoice/HandleRestore.php b/app/Services/Invoice/HandleRestore.php index a2d0177be8ce..a83dddf16b2d 100644 --- a/app/Services/Invoice/HandleRestore.php +++ b/app/Services/Invoice/HandleRestore.php @@ -12,6 +12,7 @@ namespace App\Services\Invoice; use App\Models\Invoice; +use App\Models\Paymentable; use App\Services\AbstractService; use App\Utils\Ninja; use App\Utils\Traits\GeneratesCounter; @@ -74,10 +75,14 @@ class HandleRestore extends AbstractService private function restorePaymentables() { $this->invoice->payments->each(function ($payment) { - $payment->paymentables() - ->where('paymentable_type', '=', 'invoices') - ->where('paymentable_id', $this->invoice->id) - ->update(['deleted_at' => false]); + + Paymentable::query() + ->withTrashed() + ->where('payment_id', $payment->id) + ->where('paymentable_type', '=', 'invoices') + ->where('paymentable_id', $this->invoice->id) + ->update(['deleted_at' => false]); + }); return $this;