1
|
|
|
<?php namespace Arcanedev\LaravelTracker\Models; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class Session |
5
|
|
|
* |
6
|
|
|
* @package Arcanedev\LaravelTracker\Models |
7
|
|
|
* @author ARCANEDEV <[email protected]> |
8
|
|
|
* |
9
|
|
|
* @property int id |
10
|
|
|
* @property string uuid |
11
|
|
|
* @property int user_id |
12
|
|
|
* @property int device_id |
13
|
|
|
* @property int agent_id |
14
|
|
|
* @property string client_ip |
15
|
|
|
* @property int referrer_id |
16
|
|
|
* @property int cookie_id |
17
|
|
|
* @property int geoip_id |
18
|
|
|
* @property int language_id |
19
|
|
|
* @property bool is_robot |
20
|
|
|
* @property \Carbon\Carbon created_at |
21
|
|
|
* @property \Carbon\Carbon updated_at |
22
|
|
|
* |
23
|
|
|
* @property \Illuminate\Foundation\Auth\User user |
24
|
|
|
* @property \Arcanedev\LaravelTracker\Models\Device device |
25
|
|
|
* @property \Arcanedev\LaravelTracker\Models\Agent agent |
26
|
|
|
* @property \Arcanedev\LaravelTracker\Models\Referer referer |
27
|
|
|
* @property \Arcanedev\LaravelTracker\Models\Cookie cookie |
28
|
|
|
* @property \Arcanedev\LaravelTracker\Models\GeoIp geo_ip |
29
|
|
|
* @property \Arcanedev\LaravelTracker\Models\Language language |
30
|
|
|
*/ |
31
|
|
|
class Session extends Model |
32
|
|
|
{ |
33
|
|
|
/* ------------------------------------------------------------------------------------------------ |
34
|
|
|
| Properties |
35
|
|
|
| ------------------------------------------------------------------------------------------------ |
36
|
|
|
*/ |
37
|
|
|
/** |
38
|
|
|
* The table associated with the model. |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected $table = 'sessions'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The attributes that are mass assignable. |
46
|
|
|
* |
47
|
|
|
* @var array |
48
|
|
|
*/ |
49
|
|
|
protected $fillable = [ |
50
|
|
|
'uuid', |
51
|
|
|
'user_id', |
52
|
|
|
'device_id', |
53
|
|
|
'language_id', |
54
|
|
|
'agent_id', |
55
|
|
|
'client_ip', |
56
|
|
|
'cookie_id', |
57
|
|
|
'referer_id', |
58
|
|
|
'geoip_id', |
59
|
|
|
'is_robot', |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* The attributes that should be cast to native types. |
64
|
|
|
* |
65
|
|
|
* @var array |
66
|
|
|
*/ |
67
|
|
|
protected $casts = [ |
68
|
|
|
'user_id' => 'integer', |
69
|
|
|
'device_id' => 'integer', |
70
|
|
|
'language_id' => 'integer', |
71
|
|
|
'agent_id' => 'integer', |
72
|
|
|
'cookie_id' => 'integer', |
73
|
|
|
'referer_id' => 'integer', |
74
|
|
|
'geoip_id' => 'integer', |
75
|
|
|
'is_robot' => 'boolean', |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
/* ------------------------------------------------------------------------------------------------ |
79
|
|
|
| Relationships |
80
|
|
|
| ------------------------------------------------------------------------------------------------ |
81
|
|
|
*/ |
82
|
|
|
/** |
83
|
|
|
* User relationship. |
84
|
|
|
* |
85
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
86
|
|
|
*/ |
87
|
|
|
public function user() |
88
|
|
|
{ |
89
|
|
|
return $this->belongsTo( |
90
|
|
|
$this->getConfig('models.user', \Illuminate\Foundation\Auth\User::class) |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Device relationship. |
96
|
|
|
* |
97
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
98
|
|
|
*/ |
99
|
|
|
public function device() |
100
|
|
|
{ |
101
|
|
|
return $this->belongsTo( |
102
|
|
|
$this->getConfig('models.device', Device::class) |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Agent relationship. |
108
|
|
|
* |
109
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
110
|
|
|
*/ |
111
|
|
|
public function agent() |
112
|
|
|
{ |
113
|
|
|
return $this->belongsTo( |
114
|
|
|
$this->getConfig('models.agent', Agent::class) |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Referer relationship. |
120
|
|
|
* |
121
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
122
|
|
|
*/ |
123
|
|
|
public function referer() |
124
|
|
|
{ |
125
|
|
|
return $this->belongsTo( |
126
|
|
|
$this->getConfig('models.referer', Referer::class) |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Cookie relationship. |
132
|
|
|
* |
133
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
134
|
|
|
*/ |
135
|
|
|
public function cookie() |
136
|
|
|
{ |
137
|
|
|
return $this->belongsTo( |
138
|
|
|
$this->getConfig('models.cookie', Cookie::class) |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* GeoIp relationship. |
144
|
|
|
* |
145
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
146
|
|
|
*/ |
147
|
|
|
public function geoIp() |
148
|
|
|
{ |
149
|
|
|
return $this->belongsTo( |
150
|
|
|
$this->getConfig('models.geoip', GeoIp::class), 'geoip_id' |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Language relationship. |
156
|
|
|
* |
157
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
158
|
|
|
*/ |
159
|
|
|
public function language() |
160
|
|
|
{ |
161
|
|
|
return $this->belongsTo( |
162
|
|
|
$this->getConfig('models.language', Language::class) |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|