blob: 2cb510c285d58d19e17008bedf95f606ba01f349 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<?php
namespace Lightscale\LaralightAccessLog\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Prunable;
use Illuminate\Database\Eloquent\Builder;
class AccessLog extends Model
{
use Prunable;
const UPDATED_AT = null;
protected $guarded = [
'user_id'
];
public function __construct(array $attributes = [])
{
$this->setTable(config('access_log.table_name'));
parent::__construct($attributes);
}
protected function casts(): array
{
return [
'properties' => 'collection',
];
}
public function user(): BelongsTo
{
return $this->belongsTo(config('access_log.user_model'));
}
public function prunable(): Builder
{
$days = config('access_log.max_age_days');
if ($days === null) {
return static::whereRaw('1 = 0');
}
else return static::where(static::CREATED_AT, '<=', now()->subDays($days));
}
}
|