feat: product pricing plans
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
a3894d2f37
commit
768c814762
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user