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

Размер файла: 1.29Kb
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Models;
  6.  
  7. use Illuminate\Database\Eloquent\Builder;
  8. use Illuminate\Database\Eloquent\Relations\MorphTo;
  9.  
  10. /**
  11. * Class Spam
  12. *
  13. * @property int id
  14. * @property string relate_type
  15. * @property int relate_id
  16. * @property int user_id
  17. * @property int created_at
  18. * @property string path
  19. */
  20. class Spam extends BaseModel
  21. {
  22. /**
  23. * The table associated with the model.
  24. *
  25. * @var string
  26. */
  27. protected $table = 'spam';
  28.  
  29. /**
  30. * Indicates if the model should be timestamped.
  31. *
  32. * @var bool
  33. */
  34. public $timestamps = false;
  35.  
  36. /**
  37. * The attributes that aren't mass assignable.
  38. *
  39. * @var array
  40. */
  41. protected $guarded = [];
  42.  
  43. /**
  44. * Возвращает связанные объекты
  45. *
  46. * @return MorphTo
  47. */
  48. public function relate(): MorphTo
  49. {
  50. return $this->morphTo('relate');
  51. }
  52.  
  53. /**
  54. * Возвращает объект пользователя
  55. *
  56. * @return User
  57. */
  58. public function getRelateUser(): ?User
  59. {
  60. if (! $this->relate) {
  61. return null;
  62. }
  63.  
  64. if ($this->relate->user_id || $this->relate->author_id) {
  65. return $this->relate->author ?? $this->relate->user;
  66. }
  67.  
  68. return null;
  69. }
  70. }