|
12 | 12 | use Illuminate\Foundation\Auth\User as Authenticatable; |
13 | 13 | use Illuminate\Notifications\Notifiable; |
14 | 14 | use Illuminate\Support\Facades\Auth; |
| 15 | +use Illuminate\Support\Facades\Cache; |
15 | 16 | use Spatie\MediaLibrary\HasMedia; |
16 | 17 | use Spatie\MediaLibrary\InteractsWithMedia; |
17 | 18 | use Spatie\Permission\Traits\HasRoles; |
@@ -42,6 +43,7 @@ class User extends Authenticatable implements MustVerifyEmail, HasMedia |
42 | 43 | 'phone_number', |
43 | 44 | 'github_profile', |
44 | 45 | 'twitter_profile', |
| 46 | + 'linkedin_profile', |
45 | 47 | 'website', |
46 | 48 | 'last_login_at', |
47 | 49 | 'last_login_ip', |
@@ -219,6 +221,16 @@ public function twitter(): ?string |
219 | 221 | return $this->twitter_profile; |
220 | 222 | } |
221 | 223 |
|
| 224 | + public function hasTwitterAccount(): bool |
| 225 | + { |
| 226 | + return ! empty($this->twitter()); |
| 227 | + } |
| 228 | + |
| 229 | + public function linkedin(): ?string |
| 230 | + { |
| 231 | + return $this->linkedin_profile; |
| 232 | + } |
| 233 | + |
222 | 234 | public function scopeModerators(Builder $query): Builder |
223 | 235 | { |
224 | 236 | return $query->whereHas('roles', function ($query) { |
@@ -286,19 +298,34 @@ public function routeNotificationForSlack($notification): string |
286 | 298 | return env('SLACK_WEBHOOK_URL', ''); |
287 | 299 | } |
288 | 300 |
|
289 | | - public function countReplies(): int |
| 301 | + public function replies(): Collection |
290 | 302 | { |
291 | | - return $this->replyAble()->count(); |
| 303 | + return $this->replyAble; |
292 | 304 | } |
293 | 305 |
|
294 | | - public function replies(): Collection |
| 306 | + public function countReplies(): int |
295 | 307 | { |
296 | | - return $this->replyAble; |
| 308 | + return Cache::remember('replies_count', now()->addHours(2), fn () => $this->replyAble()->count()); |
297 | 309 | } |
298 | 310 |
|
299 | 311 | public function countSolutions(): int |
300 | 312 | { |
301 | | - return $this->replyAble()->isSolution()->count(); |
| 313 | + return Cache::remember('solutions_count', now()->addHours(2), fn () => $this->replyAble()->isSolution()->count()); |
| 314 | + } |
| 315 | + |
| 316 | + public function countArticles(): int |
| 317 | + { |
| 318 | + return Cache::remember('articles_count', now()->addHours(2), fn () => $this->articles()->approved()->count()); |
| 319 | + } |
| 320 | + |
| 321 | + public function countDiscussions(): int |
| 322 | + { |
| 323 | + return Cache::remember('discussions_count', now()->addHours(2), fn () => $this->discussions()->count()); |
| 324 | + } |
| 325 | + |
| 326 | + public function countThreads(): int |
| 327 | + { |
| 328 | + return Cache::remember('threads_count', now()->addHours(2), fn () => $this->threads()->count()); |
302 | 329 | } |
303 | 330 |
|
304 | 331 | public function scopeMostSolutions(Builder $query, int $inLastDays = null) |
@@ -339,6 +366,7 @@ public function scopeMostSubmissionsInLastDays(Builder $query, int $days) |
339 | 366 | public function scopeWithCounts(Builder $query) |
340 | 367 | { |
341 | 368 | return $query->withCount([ |
| 369 | + 'articles as articles_count', |
342 | 370 | 'threads as threads_count', |
343 | 371 | 'replyAble as replies_count', |
344 | 372 | 'replyAble as solutions_count' => function (Builder $query) { |
|
0 commit comments