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