Passed
Push — activity-logs ( 8cf388 )
by Fèvre
06:45
created

ActivityLog::scopeExpires()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
namespace Xetaravel\Models;
3
4
class ActivityLog extends Model
5
{
6
7
    /**
8
     * The attributes that are mass assignable.
9
     *
10
     * @var array
11
     */
12
    protected $fillable = [
13
        'user_id',
14
        'url',
15
        'method',
16
        'ip',
17
        'user_agent',
18
        'last_activity'
19
    ];
20
21
    /**
22
     * Scope a query to only include non expired session.
23
     *
24
     * @param  \Illuminate\Database\Eloquent\Builder  $query
25
     * @return \Illuminate\Database\Eloquent\Builder
26
     */
27
    public function scopeExpires($query)
28
    {
29
        $timeout = 5; // Timeout in minutes
30
31
        $expire = time() - (60 * $timeout);
32
        return $query->where('last_activity', '>=', $expire);
33
    }
34
}
35