From 67471a3a775c49f488201be4025e7e0bea3e9feb Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Mon, 13 Mar 2023 21:44:06 -0600 Subject: [PATCH] Evaluate if the collection is empty before access the array index --- app/Http/Controllers/ReportsController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index c0c621ff68..9764df923e 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -1024,7 +1024,11 @@ class ReportsController extends Controller if (is_null($acceptance->created_at)){ return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data')); } else { - $logItem = $assetItem->checkouts()->where('created_at', '=', $acceptance->created_at)->get()[0]; + $logItem_res = $assetItem->checkouts()->where('created_at', '=', $acceptance->created_at)->get(); + if ($logItem_res->isEmpty()){ + return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data')); + } + $logItem = $logItem_res[0]; } if(!$assetItem->assignedTo->locale){