feat: product pricing plans

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Doar Mihai
2026-10-17 16:02:27 +03:00
co-authored by Claude Sonnet 5.5
parent a3894d2f37
commit 768c814762
10 changed files with 229 additions and 1 deletions
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PricingPlan extends Model
{
public const PERIODS = ['monthly', 'yearly', 'one-time'];
protected $fillable = ['product_id', 'name', 'price', 'period', 'description', 'position'];
protected function casts(): array
{
return ['price' => 'decimal:2'];
}
public function product(): BelongsTo
{
return $this->belongsTo(Product::class);
}
/**
* Price formatted for display, e.g. "€9.99" ("€0" for free plans).
*/
public function formattedPrice(): string
{
return (float) $this->price == 0 ? '€0' : '€'.number_format((float) $this->price, 2);
}
}
+8
View File
@@ -130,6 +130,14 @@ class Product extends Model
return $this->hasMany(ProductScreenshot::class)->orderBy('position')->orderBy('id');
}
/**
* Get the product's pricing plans in display order.
*/
public function pricingPlans(): HasMany
{
return $this->hasMany(PricingPlan::class)->orderBy('position')->orderBy('id');
}
/**
* Get the user that owns the product.
*/