Skip to content

Commit

Permalink
Merge pull request #1 from tochka-developers/update-requirements
Browse files Browse the repository at this point in the history
Update requirements
  • Loading branch information
yekhlakov authored Sep 9, 2022
2 parents bda3004 + 7750187 commit c4b4436
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.idea
/vendor
/composer.lock
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
22 changes: 13 additions & 9 deletions src/HistoryObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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');
}
}

0 comments on commit c4b4436

Please sign in to comment.