1 | <?php |
||
70 | class Plan extends Model implements Sortable |
||
71 | { |
||
72 | use HasSlug; |
||
73 | use SoftDeletes; |
||
74 | use SortableTrait; |
||
75 | use HasTranslations; |
||
76 | use ValidatingTrait; |
||
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | protected $fillable = [ |
||
82 | 'slug', |
||
83 | 'name', |
||
84 | 'description', |
||
85 | 'is_active', |
||
86 | 'price', |
||
87 | 'signup_fee', |
||
88 | 'currency', |
||
89 | 'trial_period', |
||
90 | 'trial_interval', |
||
91 | 'invoice_period', |
||
92 | 'invoice_interval', |
||
93 | 'grace_period', |
||
94 | 'grace_interval', |
||
95 | 'prorate_day', |
||
96 | 'prorate_period', |
||
97 | 'prorate_extend_due', |
||
98 | 'active_subscribers_limit', |
||
99 | 'sort_order', |
||
100 | ]; |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | protected $casts = [ |
||
106 | 'slug' => 'string', |
||
107 | 'is_active' => 'boolean', |
||
108 | 'price' => 'float', |
||
109 | 'signup_fee' => 'float', |
||
110 | 'currency' => 'string', |
||
111 | 'trial_period' => 'integer', |
||
112 | 'trial_interval' => 'string', |
||
113 | 'invoice_period' => 'integer', |
||
114 | 'invoice_interval' => 'string', |
||
115 | 'grace_period' => 'integer', |
||
116 | 'grace_interval' => 'string', |
||
117 | 'prorate_day' => 'integer', |
||
118 | 'prorate_period' => 'integer', |
||
119 | 'prorate_extend_due' => 'integer', |
||
120 | 'active_subscribers_limit' => 'integer', |
||
121 | 'sort_order' => 'integer', |
||
122 | 'deleted_at' => 'datetime', |
||
123 | ]; |
||
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | protected $observables = [ |
||
129 | 'validating', |
||
130 | 'validated', |
||
131 | ]; |
||
132 | |||
133 | /** |
||
134 | * The attributes that are translatable. |
||
135 | * |
||
136 | * @var array |
||
137 | */ |
||
138 | public $translatable = [ |
||
139 | 'name', |
||
140 | 'description', |
||
141 | ]; |
||
142 | |||
143 | /** |
||
144 | * The sortable settings. |
||
145 | * |
||
146 | * @var array |
||
147 | */ |
||
148 | public $sortable = [ |
||
149 | 'order_column_name' => 'sort_order', |
||
150 | ]; |
||
151 | |||
152 | /** |
||
153 | * The default rules that the model will validate against. |
||
154 | * |
||
155 | * @var array |
||
156 | */ |
||
157 | protected $rules = []; |
||
158 | |||
159 | /** |
||
160 | * Whether the model should throw a |
||
161 | * ValidationException if it fails validation. |
||
162 | * |
||
163 | * @var bool |
||
164 | */ |
||
165 | protected $throwValidationExceptions = true; |
||
166 | |||
167 | /** |
||
168 | * Create a new Eloquent model instance. |
||
169 | * |
||
170 | * @param array $attributes |
||
171 | */ |
||
172 | public function __construct(array $attributes = []) |
||
198 | |||
199 | /** |
||
200 | * Get the options for generating the slug. |
||
201 | * |
||
202 | * @return \Spatie\Sluggable\SlugOptions |
||
203 | */ |
||
204 | public function getSlugOptions(): SlugOptions |
||
211 | |||
212 | /** |
||
213 | * The plan may have many features. |
||
214 | * |
||
215 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
216 | */ |
||
217 | public function features(): HasMany |
||
221 | |||
222 | /** |
||
223 | * The plan may have many subscriptions. |
||
224 | * |
||
225 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
226 | */ |
||
227 | public function subscriptions(): HasMany |
||
231 | |||
232 | /** |
||
233 | * Check if plan is free. |
||
234 | * |
||
235 | * @return bool |
||
236 | */ |
||
237 | public function isFree(): bool |
||
241 | |||
242 | /** |
||
243 | * Check if plan has trial. |
||
244 | * |
||
245 | * @return bool |
||
246 | */ |
||
247 | public function hasTrial(): bool |
||
251 | |||
252 | /** |
||
253 | * Check if plan has grace. |
||
254 | * |
||
255 | * @return bool |
||
256 | */ |
||
257 | public function hasGrace(): bool |
||
261 | |||
262 | /** |
||
263 | * Get plan feature by the given slug. |
||
264 | * |
||
265 | * @param string $featureSlug |
||
266 | * |
||
267 | * @return \Rinvex\Subscriptions\Models\PlanFeature|null |
||
268 | */ |
||
269 | public function getFeatureBySlug(string $featureSlug): ?PlanFeature |
||
273 | |||
274 | /** |
||
275 | * Activate the plan. |
||
276 | * |
||
277 | * @return $this |
||
278 | */ |
||
279 | public function activate() |
||
285 | |||
286 | /** |
||
287 | * Deactivate the plan. |
||
288 | * |
||
289 | * @return $this |
||
290 | */ |
||
291 | public function deactivate() |
||
297 | } |
||
298 |