Files
fuel-price/app/Filament/Resources/Plans/Schemas/PlanForm.php
Ovidiu U 8695d5ec95 refactor: flatten plans.features JSON to typed columns
The features JSON column required defensive fallback stubs in three
places (Plan::resolveForUser, PlanFeatures::__construct, PlanSeeder)
and silently swallowed misspelled keys. Typed columns give Eloquent
type-safe reads, simplify the Filament form (no more dotted JSON
paths), and let resolveForUser fail loud when the free row is
missing.

PlanFeatures public API is unchanged so consumers (jobs, middleware)
need no rewrites — one missed JSON read in SendScheduledWhatsAppJob
was caught and converted to a typed where() query.

tests/Pest.php seeds PlanSeeder in beforeEach so any feature test
that resolves a plan finds the free row, mirroring production where
plans always exist.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 18:13:26 +01:00

100 lines
3.7 KiB
PHP

<?php
namespace App\Filament\Resources\Plans\Schemas;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
class PlanForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Section::make('Fuel Types')
->schema([
TextInput::make('max_fuel_types')
->label('Max fuel types')
->helperText('Leave blank for unlimited.')
->numeric()
->integer()
->minValue(1)
->nullable(),
]),
Section::make('Email')
->columns(2)
->schema([
Toggle::make('email_enabled')
->label('Enabled'),
Select::make('email_frequency')
->label('Frequency')
->options([
'weekly_digest' => 'Weekly digest',
'daily' => 'Daily',
'triggered' => 'Triggered',
]),
]),
Section::make('Push')
->columns(2)
->schema([
Toggle::make('push_enabled')
->label('Enabled'),
Select::make('push_frequency')
->label('Frequency')
->options([
'none' => 'None (disabled)',
'daily' => 'Daily',
'triggered' => 'Triggered',
]),
]),
Section::make('WhatsApp')
->columns(3)
->schema([
Toggle::make('whatsapp_enabled')
->label('Enabled'),
TextInput::make('whatsapp_daily_limit')
->label('Daily limit')
->numeric()
->integer()
->minValue(0)
->required(),
TextInput::make('whatsapp_scheduled_updates')
->label('Scheduled updates per day')
->numeric()
->integer()
->minValue(0)
->required(),
]),
Section::make('SMS')
->columns(2)
->schema([
Toggle::make('sms_enabled')
->label('Enabled'),
TextInput::make('sms_daily_limit')
->label('Daily limit')
->numeric()
->integer()
->minValue(0)
->required(),
]),
Section::make('Features')
->schema([
Toggle::make('ai_predictions')
->label('AI predictions'),
Toggle::make('price_threshold')
->label('Price threshold alerts'),
Toggle::make('score_alerts')
->label('Score change alerts'),
]),
]);
}
}