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