1 | <?php |
||
39 | class PlanSubscriptionUsage extends Model |
||
40 | { |
||
41 | use SoftDeletes; |
||
42 | use ValidatingTrait; |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | protected $fillable = [ |
||
48 | 'subscription_id', |
||
49 | 'feature_id', |
||
50 | 'used', |
||
51 | 'valid_until', |
||
52 | ]; |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | protected $casts = [ |
||
58 | 'subscription_id' => 'integer', |
||
59 | 'feature_id' => 'integer', |
||
60 | 'used' => 'integer', |
||
61 | 'valid_until' => 'datetime', |
||
62 | 'deleted_at' => 'datetime', |
||
63 | ]; |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | protected $observables = [ |
||
69 | 'validating', |
||
70 | 'validated', |
||
71 | ]; |
||
72 | |||
73 | /** |
||
74 | * The default rules that the model will validate against. |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | protected $rules = []; |
||
79 | |||
80 | /** |
||
81 | * Whether the model should throw a |
||
82 | * ValidationException if it fails validation. |
||
83 | * |
||
84 | * @var bool |
||
85 | */ |
||
86 | protected $throwValidationExceptions = true; |
||
87 | |||
88 | /** |
||
89 | * Create a new Eloquent model instance. |
||
90 | * |
||
91 | * @param array $attributes |
||
92 | */ |
||
93 | public function __construct(array $attributes = []) |
||
105 | |||
106 | /** |
||
107 | * Subscription usage always belongs to a plan feature. |
||
108 | * |
||
109 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
110 | */ |
||
111 | public function feature(): BelongsTo |
||
115 | |||
116 | /** |
||
117 | * Subscription usage always belongs to a plan subscription. |
||
118 | * |
||
119 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
120 | */ |
||
121 | public function subscription(): BelongsTo |
||
125 | |||
126 | /** |
||
127 | * Scope subscription usage by feature slug. |
||
128 | * |
||
129 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
130 | * @param string $featureSlug |
||
131 | * |
||
132 | * @return \Illuminate\Database\Eloquent\Builder |
||
133 | */ |
||
134 | public function scopeByFeatureSlug(Builder $builder, string $featureSlug): Builder |
||
135 | { |
||
136 | $feature = app('rinvex.subscriptions.plan_feature')->where('slug', $featureSlug)->first(); |
||
137 | |||
138 | return $builder->where('feature_id', $feature->getKey() ?? null); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Check whether usage has been expired or not. |
||
143 | * |
||
144 | * @return bool |
||
145 | */ |
||
146 | public function expired(): bool |
||
154 | } |
||
155 |