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

Размер файла: 1.51Kb
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Models;
  6.  
  7. use Illuminate\Database\Eloquent\Collection;
  8. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  9. use Illuminate\Database\Eloquent\Relations\HasMany;
  10. use Illuminate\Database\Eloquent\Relations\MorphMany;
  11.  
  12. /**
  13. * Class Vote
  14. *
  15. * @property int id
  16. * @property string title
  17. * @property string description
  18. * @property int count
  19. * @property int closed
  20. * @property int created_at
  21. * @property int topic_id
  22. * @property Topic topic
  23. * @property Collection answers
  24. */
  25. class Vote extends BaseModel
  26. {
  27. /**
  28. * Indicates if the model should be timestamped.
  29. *
  30. * @var bool
  31. */
  32. public $timestamps = false;
  33.  
  34. /**
  35. * The attributes that aren't mass assignable.
  36. *
  37. * @var array
  38. */
  39. protected $guarded = [];
  40.  
  41. /**
  42. * Morph name
  43. *
  44. * @var string
  45. */
  46. public static $morphName = 'votes';
  47.  
  48. /**
  49. * Возвращает топик
  50. *
  51. * @return BelongsTo
  52. */
  53. public function topic(): BelongsTo
  54. {
  55. return $this->belongsTo(Topic::class, 'topic_id')->withDefault();
  56. }
  57.  
  58. /**
  59. * Возвращает варианты ответов
  60. *
  61. * @return HasMany
  62. */
  63. public function answers(): HasMany
  64. {
  65. return $this->hasMany(VoteAnswer::class, 'vote_id')->orderBy('id');
  66. }
  67.  
  68. /**
  69. * Возвращает связь с голосованиями
  70. */
  71. public function pollings(): MorphMany
  72. {
  73. return $this->morphMany(Polling::class, 'relate');
  74. }
  75. }