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', 'quantity']; |
||
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 | 'quantity' => 'integer' |
||
38 | ]; |
||
39 | |||
40 | /** |
||
41 | * The attributes that should be mutated to dates. |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $dates = ['expires_at']; |
||
46 | |||
47 | /** |
||
48 | * Promocode constructor. |
||
49 | * |
||
50 | * @param array $attributes |
||
51 | */ |
||
52 | public function __construct(array $attributes = []) |
||
58 | |||
59 | /** |
||
60 | * Get the users who is related promocode. |
||
61 | * |
||
62 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
63 | */ |
||
64 | public function users() |
||
70 | |||
71 | /** |
||
72 | * Query builder to find promocode using code. |
||
73 | * |
||
74 | * @param $query |
||
75 | * @param $code |
||
76 | * |
||
77 | * @return mixed |
||
78 | */ |
||
79 | public function scopeByCode($query, $code) |
||
83 | |||
84 | /** |
||
85 | * Query builder to get disposable codes. |
||
86 | * |
||
87 | * @param $query |
||
88 | * @return mixed |
||
89 | */ |
||
90 | public function scopeIsDisposable($query) |
||
94 | |||
95 | /** |
||
96 | * Query builder to get non-disposable codes. |
||
97 | * |
||
98 | * @param $query |
||
99 | * @return mixed |
||
100 | */ |
||
101 | public function scopeIsNotDisposable($query) |
||
105 | |||
106 | /** |
||
107 | * Query builder to get expired promotion codes. |
||
108 | * |
||
109 | * @param $query |
||
110 | * @return mixed |
||
111 | */ |
||
112 | public function scopeExpired($query) |
||
116 | |||
117 | /** |
||
118 | * Check if code is disposable (ont-time). |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | public function isDisposable() |
||
126 | |||
127 | /** |
||
128 | * Check if code is expired. |
||
129 | * |
||
130 | * @return bool |
||
131 | */ |
||
132 | public function isExpired() |
||
136 | |||
137 | /** |
||
138 | * Check if code amount is over. |
||
139 | * |
||
140 | * @return bool |
||
141 | */ |
||
142 | public function isOverAmount() |
||
150 | } |
||
151 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: