From e74acdc6f834b885f7b0b54af162c4f74c0b4c14 Mon Sep 17 00:00:00 2001 From: Grigory Parshikov Date: Fri, 9 Sep 2022 15:32:23 +0400 Subject: [PATCH 1/3] Igore vendor/IDE/composer.lock --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e0d383d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.idea +/vendor +/composer.lock From 56bb7f4cc6eca82d928b0daa14396810c1ad9f09 Mon Sep 17 00:00:00 2001 From: Grigory Parshikov Date: Fri, 9 Sep 2022 15:32:32 +0400 Subject: [PATCH 2/3] Reformat code --- src/HistoryObserver.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/HistoryObserver.php b/src/HistoryObserver.php index 84a09d8..2d92848 100644 --- a/src/HistoryObserver.php +++ b/src/HistoryObserver.php @@ -9,6 +9,7 @@ /** * This listens for model events and produces a history record for each action on the model in question. + * * @codeCoverageIgnore */ class HistoryObserver @@ -18,6 +19,14 @@ class HistoryObserver public const ACTION_DELETE = 'delete'; public const ACTION_RESTORE = 'restore'; + protected static ?string $tableName = null; + + public static function getTableName(): string + { + return self::$tableName ?? + self::$tableName = App::make('config')->get('model-history.table_name', 'history'); + } + public function created(Model $model): void { self::saveData($model, self::ACTION_CREATE); @@ -53,15 +62,10 @@ public static function saveData(Model $model, string $action): void 'changed_at' => \date('Y-m-d H:i:s'), ]); } catch (\Throwable $t) { - Log::error('Unable to save history entry', ['entity_name' => $entity_name, 'entity_id' => $entity_id, 'message' => $t->getMessage()]); + Log::error( + 'Unable to save history entry', + ['entity_name' => $entity_name, 'entity_id' => $entity_id, 'message' => $t->getMessage()] + ); } } - - protected static ?string $tableName = null; - - public static function getTableName(): string - { - return self::$tableName ?? - self::$tableName = App::make('config')->get('model-history.table_name', 'history'); - } } From 775018798c5e0e4173497b71f104981bd00bc3b5 Mon Sep 17 00:00:00 2001 From: Grigory Parshikov Date: Fri, 9 Sep 2022 15:32:55 +0400 Subject: [PATCH 3/3] PHP 8 and Laravel 9 support --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index c8d1ab7..efb79b3 100644 --- a/composer.json +++ b/composer.json @@ -3,11 +3,11 @@ "description": "Simple history for Laravel models", "type": "package", "require": { - "php": "^7.4", + "php": "^7.4|8.0.*|8.1.*", "ext-json": "*", "ext-pdo": "*", - "illuminate/database": "^5.8 || ^6.0 || ^7.0 || ^8.0", - "illuminate/support": "^5.8 || ^6.0 || ^7.0 || ^8.0" + "illuminate/database": "^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0", + "illuminate/support": "^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0" }, "autoload": { "psr-4": {