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

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