| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
-
- namespace App\Models;
-
- use Illuminate\Database\Eloquent\Model;
-
- /**
- * One pricing plan and what it allows. The price is in sen (1 ringgit = 100 sen).
- *
- * @property int $id
- * @property string $key
- * @property string $name
- * @property int $price
- * @property int $stores
- * @property int $regenerations
- * @property int $edits
- * @property string $period
- * @property string|null $stripe_product_id
- * @property string|null $stripe_price_id
- * @property int $sort
- */
- class Plan extends Model
- {
- public static function findByKey(string $key): ?self
- {
- return static::query()->where('key', $key)->first();
- }
-
- public function isPaid(): bool
- {
- return $this->price > 0;
- }
-
- /**
- * What the dashboard is allowed to see. The price is in ringgit here.
- *
- * @return array<string, mixed>
- */
- public function toDisplay(): array
- {
- return [
- 'key' => $this->key,
- 'name' => $this->name,
- 'price' => $this->price / 100,
- 'stores' => $this->stores,
- 'regenerations' => $this->regenerations,
- 'edits' => $this->edits,
- 'period' => $this->period,
- ];
- }
-
- /**
- * @return array<string, string>
- */
- protected function casts(): array
- {
- return [
- 'price' => 'integer',
- 'stores' => 'integer',
- 'regenerations' => 'integer',
- 'edits' => 'integer',
- 'sort' => 'integer',
- ];
- }
- }
|