From 439e031911fd92f6b8317160e2351ff12362c34a Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Wed, 13 Sep 2023 16:35:10 -0600 Subject: [PATCH] Evaluate if the event properties exists before run the CheckoutAcceptance query --- app/Listeners/CheckoutableListener.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index fc86245d1a..2c27e19ecf 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -79,13 +79,15 @@ class CheckoutableListener /** * Send the appropriate notification */ - $acceptances = CheckoutAcceptance::where('checkoutable_id', $event->checkoutable->id ?? null) - ->where('assigned_to_id', $event->checkedOutTo->id ?? null) - ->get(); + if ($event->checkedOutTo && $event->checkoutable){ + $acceptances = CheckoutAcceptance::where('checkoutable_id', $event->checkoutable->id) + ->where('assigned_to_id', $event->checkedOutTo->id) + ->get(); - foreach($acceptances as $acceptance){ - if($acceptance->isPending()){ - $acceptance->delete(); + foreach($acceptances as $acceptance){ + if($acceptance->isPending()){ + $acceptance->delete(); + } } }