AaronFarm
AaronFarm
FFilament
Created by AaronFarm on 9/16/2024 in #❓┊help
Repeater with 2 Unique Key Combinations
Good morning, I have a case where a course has a cost based on a "mode" and "type". Initially, it was based only on the "mode", and this code in CourseResource worked perfectly:
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
Repeater::make('modes')
->relationship()
->schema([
Select::make('mode_id')
->label('Mode')
->options(Mode::query()->pluck('name', 'id'))
->required()
->distinct()
->disableOptionsWhenSelectedInSiblingRepeaterItems(),
TextInput::make('cost')
->numeric()
->minValue(0)
->maxValue(999999.99)
->prefix('$')
->required()
])
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
Repeater::make('modes')
->relationship()
->schema([
Select::make('mode_id')
->label('Mode')
->options(Mode::query()->pluck('name', 'id'))
->required()
->distinct()
->disableOptionsWhenSelectedInSiblingRepeaterItems(),
TextInput::make('cost')
->numeric()
->minValue(0)
->maxValue(999999.99)
->prefix('$')
->required()
])
But after adding the "type", I get errors when saving, errors when disabling the selects for the unique combination of types and modes, etc. My question is: Is there an established or standard way to handle the Repeater with 2 unique key combinations? Before: courses(id, name) modes(id, name) costs(id, [course_id, mode_id] unique, cost) Now: courses(id, name) modes(id, name) types(id, name) costs(id, [course_id, mode_id, type_id] unique, cost)
4 replies
FFilament
Created by AaronFarm on 9/8/2024 in #❓┊help
Remove routes for modals or use --simple?
Good afternoon, I have a question. To create a simple resource with modals, I know that you use php artisan make:filament-resource Customer --simple, but initially, I created the resource with the default pages for edit and create. Now I realize that I actually wanted a modal and did the following: removed the routes:
public static function getPages(): array
{
return [
'index' => Pages\ListCategory::route('/'),
// Removed:
// 'create' => Pages\CreateCategory::route('/create'),
// 'edit' => Pages\EditCategory::route('/{record}/edit'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListCategory::route('/'),
// Removed:
// 'create' => Pages\CreateCategory::route('/create'),
// 'edit' => Pages\EditCategory::route('/{record}/edit'),
];
}
Now they are modals, but my question is: is this approach really okay? Would there be any issues with this method, or should I use --simple? I noticed that --simple creates a slightly different structure, only creating a management page in the resources folder.
3 replies
FFilament
Created by AaronFarm on 9/5/2024 in #❓┊help
Custom Toggle
Is it possible to obtain the current record and the state of the toggle, true or false, in order to perform operations when saving or updating the form, so that based on that record and toggle state, custom operations can be performed, such as creating or editing other different models and the database? Forms\Components\Toggle::make('custom'),
7 replies