Device::user()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Lab404\AuthChecker\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\HasMany;
7
use Illuminate\Database\Eloquent\Relations\HasOne;
8
use Illuminate\Database\Eloquent\Relations\MorphTo;
9
10
/**
11
 * @package Lab404\AuthChecker\Models
12
 * @property int                                        $id
13
 * @property \Lab404\AuthChecker\Models\Login           $login
14
 * @property \Lab404\AuthChecker\Models\Login[]         $logins
15
 * @property \Illuminate\Contracts\Auth\Authenticatable $user
16
 * @property int                                        $user_id
17
 * @property string                                     $user_type
18
 * @property string                                     $platform
19
 * @property string                                     $platform_version
20
 * @property string                                     $browser
21
 * @property string                                     $browser_version
22
 * @property bool                                       $is_desktop
23
 * @property bool                                       $is_mobile
24
 * @property string                                     $language
25
 * @property \Carbon\Carbon                             $created_at
26
 * @property \Carbon\Carbon                             $updated_at
27
 */
28
class Device extends Model
29
{
30
    /** @var array $casts */
31
    protected $casts = [
32
        'is_locked' => 'boolean',
33
        'is_desktop' => 'boolean',
34
        'is_phone' => 'boolean',
35
    ];
36
    /** @var array $fillable */
37
    protected $fillable = [
38
        'platform',
39
        'platform_version',
40
        'browser',
41
        'browser_version',
42
        'is_desktop',
43
        'is_phone',
44
        'is_trusted',
45
        'is_untrusted',
46
    ];
47
48
    public function logins(): HasMany
49
    {
50
        $model = config('auth-checker.models.login') ?? Login::class;
51
52
        return $this->hasMany($model);
53
    }
54
55
    public function login(): HasOne
56
    {
57
        $model = config('auth-checker.models.login') ?? Login::class;
58
59
        $relation = $this->hasOne($model);
60
        $relation->orderBy('created_at', 'desc');
61
        return $relation;
62
    }
63
64
    public function user(): MorphTo
65
    {
66
        return $this->morphTo();
67
    }
68
}
69