diff options
| author | Sam Light <samlight1994@gmail.com> | 2025-04-09 22:42:43 +0100 | 
|---|---|---|
| committer | Sam Light <samlight1994@gmail.com> | 2025-04-09 22:42:43 +0100 | 
| commit | 254b5f1abfdec2a051988150d7c36df43f455cc1 (patch) | |
| tree | 0d0dad0ff54c3a5aa425216e9294c4aa02a32691 /src/Models/AuthLog.php | |
Initial commit
Diffstat (limited to 'src/Models/AuthLog.php')
| -rw-r--r-- | src/Models/AuthLog.php | 47 | 
1 files changed, 47 insertions, 0 deletions
| 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 @@ +<?php + +namespace Lightscale\LaralightAuthLog\Models; + +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Prunable; +use Illuminate\Database\Eloquent\Builder; + +class AuthLog extends Model +{ +    use Prunable; + +    const UPDATED_AT = null; + +    protected $guarded = [ +        'user_id' +    ]; + +    public function __construct(array $attributes = []) +    { +        $this->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)); +    } +} | 
