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