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