1 | <?php |
||
41 | class Session extends Model |
||
42 | { |
||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | public $incrementing = false; |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | protected $fillable = [ |
||
52 | 'id', |
||
53 | 'user_id', |
||
54 | 'user_type', |
||
55 | 'ip_address', |
||
56 | 'user_agent', |
||
57 | 'payload', |
||
58 | 'last_activity', |
||
59 | ]; |
||
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | protected $casts = [ |
||
65 | 'user_id' => 'integer', |
||
66 | 'user_type' => 'string', |
||
67 | 'ip_address' => 'string', |
||
68 | 'user_agent' => 'string', |
||
69 | 'payload' => 'string', |
||
70 | 'last_activity' => 'datetime', |
||
71 | ]; |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | public $timestamps = false; |
||
77 | |||
78 | /** |
||
79 | * Create a new Eloquent model instance. |
||
80 | * |
||
81 | * @param array $attributes |
||
82 | */ |
||
83 | public function __construct(array $attributes = []) |
||
89 | |||
90 | /** |
||
91 | * Add an "order by" clause to retrieve most recent sessions. |
||
92 | * |
||
93 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
94 | * @param string $column |
||
95 | * |
||
96 | * @return \Illuminate\Database\Eloquent\Builder |
||
97 | */ |
||
98 | public function scopeMostRecent(Builder $builder, $column = 'last_activity'): Builder |
||
102 | |||
103 | /** |
||
104 | * Add an "order by" clause to retrieve least recent sessions. |
||
105 | * |
||
106 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
107 | * @param string $column |
||
108 | * |
||
109 | * @return \Illuminate\Database\Eloquent\Builder |
||
110 | */ |
||
111 | public function scopeLeastRecent(Builder $builder, $column = 'last_activity'): Builder |
||
115 | |||
116 | /** |
||
117 | * Constrain the query to retrieve only sessions of guests who |
||
118 | * have been active within the specified number of seconds. |
||
119 | * |
||
120 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
121 | * @param int $seconds |
||
122 | * |
||
123 | * @return \Illuminate\Database\Eloquent\Builder |
||
124 | */ |
||
125 | public function scopeGuestsBySeconds(Builder $builder, $seconds = 60): Builder |
||
129 | |||
130 | /** |
||
131 | * Alias for the `guestsByMinutes` query method. |
||
132 | * |
||
133 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
134 | * @param int $minutes |
||
135 | * |
||
136 | * @return \Illuminate\Database\Eloquent\Builder |
||
137 | */ |
||
138 | public function scopeGuests(Builder $builder, $minutes = 5): Builder |
||
142 | |||
143 | /** |
||
144 | * Constrain the query to retrieve only sessions of guests who |
||
145 | * have been active within the specified number of minutes. |
||
146 | * |
||
147 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
148 | * @param int $minutes |
||
149 | * |
||
150 | * @return \Illuminate\Database\Eloquent\Builder |
||
151 | */ |
||
152 | public function scopeGuestsByMinutes(Builder $builder, $minutes = 5): Builder |
||
156 | |||
157 | /** |
||
158 | * Constrain the query to retrieve only sessions of guests who |
||
159 | * have been active within the specified number of hours. |
||
160 | * |
||
161 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
162 | * @param int $hours |
||
163 | * |
||
164 | * @return \Illuminate\Database\Eloquent\Builder |
||
165 | */ |
||
166 | public function scopeGuestsByHours(Builder $builder, $hours = 1): Builder |
||
170 | |||
171 | /** |
||
172 | * Constrain the query to retrieve only sessions of users who |
||
173 | * have been active within the specified number of seconds. |
||
174 | * |
||
175 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
176 | * @param int $seconds |
||
177 | * |
||
178 | * @return \Illuminate\Database\Eloquent\Builder |
||
179 | */ |
||
180 | public function scopeUsersBySeconds(Builder $builder, $seconds = 60): Builder |
||
184 | |||
185 | /** |
||
186 | * Constrain the query to retrieve only sessions of users who |
||
187 | * have been active within the specified number of minutes. |
||
188 | * |
||
189 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
190 | * @param int $minutes |
||
191 | * |
||
192 | * @return \Illuminate\Database\Eloquent\Builder |
||
193 | */ |
||
194 | public function scopeUsersByMinutes(Builder $builder, $minutes = 5): Builder |
||
198 | |||
199 | /** |
||
200 | * Constrain the query to retrieve only sessions of users who |
||
201 | * have been active within the specified number of hours. |
||
202 | * |
||
203 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
204 | * @param int $hours |
||
205 | * |
||
206 | * @return \Illuminate\Database\Eloquent\Builder |
||
207 | */ |
||
208 | public function scopeUsersByHours(Builder $builder, $hours = 1): Builder |
||
212 | |||
213 | /** |
||
214 | * Get the owning user. |
||
215 | * |
||
216 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
217 | */ |
||
218 | public function user(): MorphTo |
||
222 | |||
223 | /** |
||
224 | * Get sessions of the given user. |
||
225 | * |
||
226 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
227 | * @param \Illuminate\Database\Eloquent\Model $user |
||
228 | * |
||
229 | * @return \Illuminate\Database\Eloquent\Builder |
||
230 | */ |
||
231 | public function scopeOfUser(Builder $builder, Model $user): Builder |
||
235 | } |
||
236 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.