From 254b5f1abfdec2a051988150d7c36df43f455cc1 Mon Sep 17 00:00:00 2001 From: Sam Light Date: Wed, 9 Apr 2025 22:42:43 +0100 Subject: Initial commit --- src/AuthLogServiceProvider.php | 24 +++++++++++++++++++++ src/Models/AuthLog.php | 47 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/AuthLogServiceProvider.php create mode 100644 src/Models/AuthLog.php (limited to 'src') diff --git a/src/AuthLogServiceProvider.php b/src/AuthLogServiceProvider.php new file mode 100644 index 0000000..55cc2c2 --- /dev/null +++ b/src/AuthLogServiceProvider.php @@ -0,0 +1,24 @@ +publishesMigrations([ + "{$root}/database/migrations" => database_path('migrations', "{$ns}:migrations"), + ]); + + $this->mergeConfigFrom("$root/config/auth_log.php", 'auth_log'); + $this->publishes([ + "{$root}/config/access_log.php" => config_path('auth_log.php'), + ], "{$ns}:config"); + } +} diff --git a/src/Models/AuthLog.php b/src/Models/AuthLog.php new file mode 100644 index 0000000..a5b1280 --- /dev/null +++ b/src/Models/AuthLog.php @@ -0,0 +1,47 @@ +setTable(config('auth_log.table_name')); + + parent::__construct($attributes); + } + + protected function casts(): array + { + return [ + 'properties' => 'collection', + ]; + } + + public function user(): BelongsTo + { + return $this->belongsTo(config('auth_log.user_model')); + } + + public function prunable(): Builder + { + $days = config('auth_log.max_age_days'); + if ($days === null) { + return static::whereRaw('1 = 0'); + } + else return static::where(static::CREATED_AT, '<=', now()->subDays($days)); + } +} -- cgit v1.2.3