Просмотр файла app/Models/AdminAdvert.php

Размер файла: 1.56Kb
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Models;
  6.  
  7. use Illuminate\Support\Facades\Cache;
  8.  
  9. /**
  10. * Class Advert
  11. *
  12. * @property int id
  13. * @property string site
  14. * @property string name
  15. * @property string color
  16. * @property int bold
  17. * @property int user_id
  18. * @property int created_at
  19. * @property int deleted_at
  20. */
  21. class AdminAdvert extends BaseModel
  22. {
  23. /**
  24. * Indicates if the model should be timestamped.
  25. *
  26. * @var bool
  27. */
  28. public $timestamps = false;
  29.  
  30. /**
  31. * The attributes that aren't mass assignable.
  32. *
  33. * @var array
  34. */
  35. protected $guarded = [];
  36.  
  37. /**
  38. * Кэширует ссылки админской рекламы
  39. *
  40. * @return array Список ссылок
  41. */
  42. public static function statAdverts(): array
  43. {
  44. return Cache::remember('adminAdverts', 1800, static function () {
  45. $data = self::query()->where('deleted_at', '>', SITETIME)->get();
  46.  
  47. $links = [];
  48. if ($data->isNotEmpty()) {
  49. foreach ($data as $val) {
  50. $name = check($val->name);
  51.  
  52. if ($val->color) {
  53. $name = '<span style="color:' . $val->color . '">' . $name . '</span>';
  54. }
  55.  
  56. $link = '<a href="' . $val->site . '" target="_blank">' . $name . '</a>';
  57.  
  58. if ($val->bold) {
  59. $link = '<b>' . $link . '</b>';
  60. }
  61.  
  62. $links[] = $link;
  63. }
  64. }
  65.  
  66. return $links;
  67. });
  68. }
  69. }