feat: add plan_prices table, PlanPrice model, and Plan relationship
- Create plan_prices migration with unique(plan_id, billing_cycle) - PlanPrice model with factory - Plan::prices() relationship and priceForCycle() helper - Tests for model relationships, uniqueness, cascade delete Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -49,6 +49,16 @@ class Plan extends Model
|
||||
return $this->hasMany(Service::class);
|
||||
}
|
||||
|
||||
public function prices(): HasMany
|
||||
{
|
||||
return $this->hasMany(PlanPrice::class);
|
||||
}
|
||||
|
||||
public function priceForCycle(string $cycle): ?PlanPrice
|
||||
{
|
||||
return $this->prices()->where('billing_cycle', $cycle)->first();
|
||||
}
|
||||
|
||||
public function isAvailable(): bool
|
||||
{
|
||||
if ($this->status !== 'active') {
|
||||
|
||||
33
website/app/Models/PlanPrice.php
Normal file
33
website/app/Models/PlanPrice.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PlanPrice extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'plan_id',
|
||||
'billing_cycle',
|
||||
'price',
|
||||
'stripe_price_id',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'price' => 'decimal:2',
|
||||
];
|
||||
}
|
||||
|
||||
public function plan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Plan::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user