1 | <?php |
||
8 | class Promocode extends Model |
||
9 | { |
||
10 | /** |
||
11 | * Indicates if the model should be timestamped. |
||
12 | * |
||
13 | * @var bool |
||
14 | */ |
||
15 | public $timestamps = false; |
||
16 | |||
17 | /** |
||
18 | * The attributes that are mass assignable. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $fillable = ['code', 'reward', 'is_disposable', 'expires_at']; |
||
23 | |||
24 | /** |
||
25 | * The attributes that should be cast to native types. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $casts = [ |
||
30 | 'is_disposable' => 'boolean', |
||
31 | 'data' => 'array', |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * The attributes that should be mutated to dates. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $dates = ['expires_at']; |
||
40 | |||
41 | /** |
||
42 | * Promocode constructor. |
||
43 | * |
||
44 | * @param array $attributes |
||
45 | */ |
||
46 | public function __construct(array $attributes = []) |
||
52 | |||
53 | /** |
||
54 | * Get the users who is related promocode. |
||
55 | * |
||
56 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
57 | */ |
||
58 | public function users() |
||
63 | |||
64 | /** |
||
65 | * Query builder to find promocode using code. |
||
66 | * |
||
67 | * @param $query |
||
68 | * @param $code |
||
69 | * |
||
70 | * @return mixed |
||
71 | */ |
||
72 | public function scopeByCode($query, $code) |
||
76 | |||
77 | /** |
||
78 | * Query builder to get disposable codes. |
||
79 | * |
||
80 | * @param $query |
||
81 | * @return mixed |
||
82 | */ |
||
83 | public function scopeIsDisposable($query) |
||
87 | |||
88 | /** |
||
89 | * Query builder to get non-disposable codes. |
||
90 | * |
||
91 | * @param $query |
||
92 | * @return mixed |
||
93 | */ |
||
94 | public function scopeIsNotDisposable($query) |
||
98 | |||
99 | /** |
||
100 | * Query builder to get expired promotion codes. |
||
101 | * |
||
102 | * @param $query |
||
103 | * @return mixed |
||
104 | */ |
||
105 | public function scopeExpired($query) |
||
109 | |||
110 | /** |
||
111 | * Check if code is disposable (ont-time). |
||
112 | * |
||
113 | * @return bool |
||
114 | */ |
||
115 | public function isDisposable() |
||
119 | |||
120 | /** |
||
121 | * Check if code is expired. |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | public function isExpired() |
||
129 | } |
||
130 |