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:
Claude Dev
2026-03-14 23:31:12 -04:00
parent b2fd5abc7e
commit c034be820e
5 changed files with 232 additions and 0 deletions

View File

@@ -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') {

View 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);
}
}