From 7beb161d2bd324850743ca205559cb52386c77c6 Mon Sep 17 00:00:00 2001 From: KJ Date: Sun, 2 Jun 2024 11:31:37 -0400 Subject: [PATCH] Ensure db is in transaction to commit or rollback. --- src/Libs/Model.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Libs/Model.php b/src/Libs/Model.php index 0d85b24..965b3f9 100644 --- a/src/Libs/Model.php +++ b/src/Libs/Model.php @@ -85,7 +85,10 @@ class Model { */ public function rollBack(): bool { - return static::db()->rollBack(); + if ( static::db()->inTransaction()) + return static::db()->rollBack(); + else + return true; } /** @@ -96,7 +99,10 @@ class Model { */ public function commit(): bool { - return static::db()->commit(); + if (static::db()->inTransaction()) + return static::db()->commit(); + else + return true; } /**