1 | <?php namespace Arcanedev\LaravelTracker\Models; |
||
31 | class Session extends AbstractModel |
||
32 | { |
||
33 | /* ------------------------------------------------------------------------------------------------ |
||
34 | | Traits |
||
35 | | ------------------------------------------------------------------------------------------------ |
||
36 | */ |
||
37 | use Presenters\SessionPresenter; |
||
38 | |||
39 | /* ------------------------------------------------------------------------------------------------ |
||
40 | | Properties |
||
41 | | ------------------------------------------------------------------------------------------------ |
||
42 | */ |
||
43 | /** |
||
44 | * The table associated with the model. |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $table = 'sessions'; |
||
49 | |||
50 | /** |
||
51 | * The attributes that are mass assignable. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $fillable = [ |
||
56 | 'uuid', |
||
57 | 'user_id', |
||
58 | 'device_id', |
||
59 | 'language_id', |
||
60 | 'agent_id', |
||
61 | 'client_ip', |
||
62 | 'cookie_id', |
||
63 | 'referer_id', |
||
64 | 'geoip_id', |
||
65 | 'is_robot', |
||
66 | ]; |
||
67 | |||
68 | /** |
||
69 | * The attributes that should be cast to native types. |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $casts = [ |
||
74 | 'user_id' => 'integer', |
||
75 | 'device_id' => 'integer', |
||
76 | 'language_id' => 'integer', |
||
77 | 'agent_id' => 'integer', |
||
78 | 'cookie_id' => 'integer', |
||
79 | 'referer_id' => 'integer', |
||
80 | 'geoip_id' => 'integer', |
||
81 | 'is_robot' => 'boolean', |
||
82 | ]; |
||
83 | |||
84 | /* ------------------------------------------------------------------------------------------------ |
||
85 | | Relationships |
||
86 | | ------------------------------------------------------------------------------------------------ |
||
87 | */ |
||
88 | /** |
||
89 | * User relationship. |
||
90 | * |
||
91 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
92 | */ |
||
93 | public function user() |
||
99 | |||
100 | /** |
||
101 | * Device relationship. |
||
102 | * |
||
103 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
104 | */ |
||
105 | public function device() |
||
111 | |||
112 | /** |
||
113 | * Agent relationship. |
||
114 | * |
||
115 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
116 | */ |
||
117 | public function agent() |
||
123 | |||
124 | /** |
||
125 | * Referer relationship. |
||
126 | * |
||
127 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
128 | */ |
||
129 | public function referer() |
||
135 | |||
136 | /** |
||
137 | * Cookie relationship. |
||
138 | * |
||
139 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
140 | */ |
||
141 | public function cookie() |
||
147 | |||
148 | /** |
||
149 | * GeoIp relationship. |
||
150 | * |
||
151 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
152 | */ |
||
153 | public function geoip() |
||
154 | { |
||
155 | return $this->belongsTo( |
||
156 | $this->getModelClass(self::MODEL_GEOIP, GeoIp::class), 'geoip_id' |
||
157 | ); |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * Language relationship. |
||
162 | * |
||
163 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
164 | */ |
||
165 | public function language() |
||
171 | |||
172 | /** |
||
173 | * Session activities relationship. |
||
174 | * |
||
175 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
176 | */ |
||
177 | public function activities() |
||
183 | |||
184 | /* ------------------------------------------------------------------------------------------------ |
||
185 | | Check Functions |
||
186 | | ------------------------------------------------------------------------------------------------ |
||
187 | */ |
||
188 | /** |
||
189 | * Check if the user exists. |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | public function hasUser() |
||
197 | |||
198 | /** |
||
199 | * Check if the geoip exists. |
||
200 | * |
||
201 | * @return bool |
||
202 | */ |
||
203 | public function hasGeoip() |
||
207 | } |
||
208 |