-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOption.php
66 lines (58 loc) · 1015 Bytes
/
Option.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
66
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Option extends Model
{
/**
* Massive assign
*
* @var array
*/
protected $fillable = [
'type', 'content',
];
/**
* Table name plz
*
* @var string
*/
protected $table = 'question_options';
/**
* Trace back to the question
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function question()
{
return $this->belongsTo('App\Question', 'question_id', 'id');
}
/**
* Option Counts
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function answers()
{
return $this->hasMany('App\Answer', 'option_id', 'id');
}
/**
* Popular search Id
*
* @param $query
* @param $Id
* @return mixed
*/
public function scopeId($query, $Id)
{
return $query->where('id', $Id)->firstOrFail();
}
/**
* Get total number of people who choose certain option
*
* @return int
*/
public function getTotalNumber()
{
return count($this->answers);
}
}