From 838c45332d864590e20c96fef2e0980554b961c4 Mon Sep 17 00:00:00 2001 From: Patrick Mulligan Date: Fri, 26 Apr 2024 08:30:45 -0400 Subject: [PATCH] fix(Orders): ensure products created that will be first of a category gracefully defaults to 0 as the starting sequence value. --- app/Modules/Orders/Models/Product.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/Modules/Orders/Models/Product.php b/app/Modules/Orders/Models/Product.php index 8b5554229..ad4692aea 100755 --- a/app/Modules/Orders/Models/Product.php +++ b/app/Modules/Orders/Models/Product.php @@ -113,12 +113,11 @@ public static function boot(): void // Set sequence value for new entries if (!$model->id) { - $sequence = self::query() + $sequenceModel = self::query() ->where('ordercategoryid', '=', $model->ordercategoryid) ->orderBy('sequence', 'desc') - ->first() - ->sequence; - + ->first(); + $sequence = $sequenceModel->sequence ?? 0; $model->sequence = intval($sequence) + 1; } });