1 | <?php |
||
13 | class Promocode extends Model |
||
14 | { |
||
15 | /** |
||
16 | * Indicates if the model should be timestamped. |
||
17 | * |
||
18 | * @var bool |
||
19 | */ |
||
20 | public $timestamps = false; |
||
21 | |||
22 | /** |
||
23 | * The attributes that are mass assignable. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $fillable = ['code', 'reward', 'is_disposable', 'expires_at', 'amount_codes']; |
||
28 | |||
29 | /** |
||
30 | * The attributes that should be cast to native types. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $casts = [ |
||
35 | 'is_disposable' => 'boolean', |
||
36 | 'data' => 'array', |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * The attributes that should be mutated to dates. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $dates = ['expires_at']; |
||
45 | |||
46 | /** |
||
47 | * Promocode constructor. |
||
48 | * |
||
49 | * @param array $attributes |
||
50 | */ |
||
51 | public function __construct(array $attributes = []) |
||
57 | |||
58 | /** |
||
59 | * Get the users who is related promocode. |
||
60 | * |
||
61 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
62 | */ |
||
63 | public function users() |
||
69 | |||
70 | /** |
||
71 | * Query builder to find promocode using code. |
||
72 | * |
||
73 | * @param $query |
||
74 | * @param $code |
||
75 | * |
||
76 | * @return mixed |
||
77 | */ |
||
78 | public function scopeByCode($query, $code) |
||
82 | |||
83 | /** |
||
84 | * Query builder to get disposable codes. |
||
85 | * |
||
86 | * @param $query |
||
87 | * @return mixed |
||
88 | */ |
||
89 | public function scopeIsDisposable($query) |
||
93 | |||
94 | /** |
||
95 | * Query builder to get non-disposable codes. |
||
96 | * |
||
97 | * @param $query |
||
98 | * @return mixed |
||
99 | */ |
||
100 | public function scopeIsNotDisposable($query) |
||
104 | |||
105 | /** |
||
106 | * Query builder to get expired promotion codes. |
||
107 | * |
||
108 | * @param $query |
||
109 | * @return mixed |
||
110 | */ |
||
111 | public function scopeExpired($query) |
||
115 | |||
116 | /** |
||
117 | * Check if code is disposable (ont-time). |
||
118 | * |
||
119 | * @return bool |
||
120 | */ |
||
121 | public function isDisposable() |
||
125 | |||
126 | /** |
||
127 | * Check if code is expired. |
||
128 | * |
||
129 | * @return bool |
||
130 | */ |
||
131 | public function isExpired() |
||
135 | |||
136 | /** |
||
137 | * Check if code amount is over. |
||
138 | * |
||
139 | * @return bool |
||
140 | */ |
||
141 | public function isOverAmount() |
||
149 | } |
||
150 |