Files

32 lines
763 B
PHP
Raw Permalink Normal View History

2026-10-17 16:02:27 +03:00
<?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);
}
}