Total Complexity | 6 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | class RedeemCode extends Model |
||
8 | { |
||
9 | |||
10 | protected $fillable = ['event_id', 'code', 'redeemed', 'reusable']; |
||
11 | protected $visible = ['event_id', 'code', 'reusable', 'rewards']; |
||
12 | protected $appends = ['rewards']; |
||
13 | |||
14 | public static function findByCode($code) |
||
15 | { |
||
16 | return SELF::where('code', $code)->first(); |
||
17 | } |
||
18 | |||
19 | public function event() |
||
20 | { |
||
21 | return $this->belongsTo('Furic\RedeemCodes\Event'); |
||
22 | } |
||
23 | |||
24 | public function rewards() |
||
25 | { |
||
26 | if ($this->event != null) { |
||
27 | return $this->event->hasMany('Furic\RedeemCodes\RedeemCodeReward'); |
||
28 | } else { |
||
29 | return $this->hasMany('Furic\RedeemCodes\RedeemCodeReward'); |
||
30 | } |
||
31 | } |
||
32 | |||
33 | public function getRewardsAttribute() |
||
34 | { |
||
35 | return $this->rewards()->get(); |
||
36 | } |
||
37 | |||
38 | public function setRedeemed() |
||
42 | } |
||
43 | |||
44 | } |
||
45 |