Repo rebuild
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PlatformPrice extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name',
|
||||
'strapline',
|
||||
'description',
|
||||
'monthly_amount',
|
||||
'annual_amount',
|
||||
'currency',
|
||||
'badge_label',
|
||||
'features',
|
||||
'sort_order',
|
||||
'is_featured',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'features' => 'array',
|
||||
'monthly_amount' => 'integer',
|
||||
'annual_amount' => 'integer',
|
||||
'sort_order' => 'integer',
|
||||
'is_featured' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Scope prices into display order.
|
||||
*/
|
||||
public function scopeOrdered(Builder $query): Builder
|
||||
{
|
||||
return $query->orderBy('sort_order')->orderBy('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the display currency symbol.
|
||||
*/
|
||||
public function currencySymbol(): string
|
||||
{
|
||||
return match (strtolower($this->currency)) {
|
||||
'gbp' => '£',
|
||||
'eur' => '€',
|
||||
'usd' => '$',
|
||||
default => strtoupper($this->currency) . ' ',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a stored minor-unit amount for display.
|
||||
*/
|
||||
public function formatAmount(?int $amount): string
|
||||
{
|
||||
if ($amount === null) {
|
||||
return '—';
|
||||
}
|
||||
|
||||
return $this->currencySymbol() . number_format($amount / 100, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return normalised feature rows.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function featureRows(): array
|
||||
{
|
||||
return collect($this->features ?? [])
|
||||
->filter(fn ($feature): bool => is_string($feature) && trim($feature) !== '')
|
||||
->map(fn (string $feature): string => trim($feature))
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user