1 | <?php |
||
74 | class Plan extends Model implements PlanContract, Sortable |
||
75 | { |
||
76 | use HasSlug; |
||
77 | use SortableTrait; |
||
78 | use HasTranslations; |
||
79 | use ValidatingTrait; |
||
80 | use CacheableEloquent; |
||
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | protected $fillable = [ |
||
86 | 'slug', |
||
87 | 'name', |
||
88 | 'description', |
||
89 | 'is_active', |
||
90 | 'price', |
||
91 | 'signup_fee', |
||
92 | 'currency', |
||
93 | 'trial_period', |
||
94 | 'trial_interval', |
||
95 | 'invoice_period', |
||
96 | 'invoice_interval', |
||
97 | 'grace_period', |
||
98 | 'grace_interval', |
||
99 | 'prorate_day', |
||
100 | 'prorate_period', |
||
101 | 'prorate_extend_due', |
||
102 | 'active_subscribers_limit', |
||
103 | 'sort_order', |
||
104 | ]; |
||
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | protected $casts = [ |
||
110 | 'slug' => 'string', |
||
111 | 'is_active' => 'boolean', |
||
112 | 'price' => 'float', |
||
113 | 'signup_fee' => 'float', |
||
114 | 'currency' => 'string', |
||
115 | 'trial_period' => 'integer', |
||
116 | 'trial_interval' => 'string', |
||
117 | 'invoice_period' => 'integer', |
||
118 | 'invoice_interval' => 'string', |
||
119 | 'grace_period' => 'integer', |
||
120 | 'grace_interval' => 'string', |
||
121 | 'prorate_day' => 'integer', |
||
122 | 'prorate_period' => 'integer', |
||
123 | 'prorate_extend_due' => 'integer', |
||
124 | 'active_subscribers_limit' => 'integer', |
||
125 | 'sort_order' => 'integer', |
||
126 | 'deleted_at' => 'datetime', |
||
127 | ]; |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | protected $observables = [ |
||
133 | 'validating', |
||
134 | 'validated', |
||
135 | ]; |
||
136 | |||
137 | /** |
||
138 | * The attributes that are translatable. |
||
139 | * |
||
140 | * @var array |
||
141 | */ |
||
142 | public $translatable = [ |
||
143 | 'name', |
||
144 | 'description', |
||
145 | ]; |
||
146 | |||
147 | /** |
||
148 | * The sortable settings. |
||
149 | * |
||
150 | * @var array |
||
151 | */ |
||
152 | public $sortable = [ |
||
153 | 'order_column_name' => 'sort_order', |
||
154 | ]; |
||
155 | |||
156 | /** |
||
157 | * The default rules that the model will validate against. |
||
158 | * |
||
159 | * @var array |
||
160 | */ |
||
161 | protected $rules = []; |
||
162 | |||
163 | /** |
||
164 | * Whether the model should throw a |
||
165 | * ValidationException if it fails validation. |
||
166 | * |
||
167 | * @var bool |
||
168 | */ |
||
169 | protected $throwValidationExceptions = true; |
||
170 | |||
171 | /** |
||
172 | * Create a new Eloquent model instance. |
||
173 | * |
||
174 | * @param array $attributes |
||
175 | */ |
||
176 | public function __construct(array $attributes = []) |
||
202 | |||
203 | /** |
||
204 | * Get the active plans. |
||
205 | * |
||
206 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
207 | * |
||
208 | * @return \Illuminate\Database\Eloquent\Builder |
||
209 | */ |
||
210 | public function scopeActive(Builder $builder): Builder |
||
214 | |||
215 | /** |
||
216 | * Get the inactive plans. |
||
217 | * |
||
218 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
219 | * |
||
220 | * @return \Illuminate\Database\Eloquent\Builder |
||
221 | */ |
||
222 | public function scopeInactive(Builder $builder): Builder |
||
226 | |||
227 | /** |
||
228 | * Get the options for generating the slug. |
||
229 | * |
||
230 | * @return \Spatie\Sluggable\SlugOptions |
||
231 | */ |
||
232 | public function getSlugOptions(): SlugOptions |
||
239 | |||
240 | /** |
||
241 | * The plan may have many features. |
||
242 | * |
||
243 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
244 | */ |
||
245 | public function features(): HasMany |
||
249 | |||
250 | /** |
||
251 | * The plan may have many subscriptions. |
||
252 | * |
||
253 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
254 | */ |
||
255 | public function subscriptions(): HasMany |
||
259 | |||
260 | /** |
||
261 | * Check if plan is free. |
||
262 | * |
||
263 | * @return bool |
||
264 | */ |
||
265 | public function isFree(): bool |
||
269 | |||
270 | /** |
||
271 | * Check if plan has trial. |
||
272 | * |
||
273 | * @return bool |
||
274 | */ |
||
275 | public function hasTrial(): bool |
||
279 | |||
280 | /** |
||
281 | * Check if plan has grace. |
||
282 | * |
||
283 | * @return bool |
||
284 | */ |
||
285 | public function hasGrace(): bool |
||
289 | |||
290 | /** |
||
291 | * Get plan feature by the given slug. |
||
292 | * |
||
293 | * @param string $featureSlug |
||
294 | * |
||
295 | * @return \Rinvex\Subscriptions\Models\PlanFeature|null |
||
296 | */ |
||
297 | public function getFeatureBySlug(string $featureSlug) |
||
301 | |||
302 | /** |
||
303 | * Activate the plan. |
||
304 | * |
||
305 | * @return $this |
||
306 | */ |
||
307 | public function activate() |
||
313 | |||
314 | /** |
||
315 | * Deactivate the plan. |
||
316 | * |
||
317 | * @return $this |
||
318 | */ |
||
319 | public function deactivate() |
||
325 | } |
||
326 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.