caweren
caweren
FFilament
Created by caweren on 10/31/2024 in #❓┊help
Array of `Select` doesn't fill from state
I'm making a system that maps CSV columns to an existing table. For this i have a TableMapping model and resource with a single json field (key-value pairs). I have casted this field to object in the model, my resource looks like this:
public static function form(Form $form): Form
{
$schema = [];
$dbTypes = DB::select('SELECT * FROM pragma_table_info(\'sor_organisations\')');
$dbToOptions = array_combine(array_map(fn($type) => $type->name, $dbTypes), array_map(fn($type) => $type->name, $dbTypes));
foreach ($form->getRecord()->mapping as $key => $value) {
$schema[] = Forms\Components\Select::make('mapping.' . $key)
->label($key)
->options($dbToOptions)
->statePath('mapping.' . $key)
->default($value);
}
return $form
->schema($schema)->columns(1);
}
public static function form(Form $form): Form
{
$schema = [];
$dbTypes = DB::select('SELECT * FROM pragma_table_info(\'sor_organisations\')');
$dbToOptions = array_combine(array_map(fn($type) => $type->name, $dbTypes), array_map(fn($type) => $type->name, $dbTypes));
foreach ($form->getRecord()->mapping as $key => $value) {
$schema[] = Forms\Components\Select::make('mapping.' . $key)
->label($key)
->options($dbToOptions)
->statePath('mapping.' . $key)
->default($value);
}
return $form
->schema($schema)->columns(1);
}
This all works fine, i get all the dropdowns, along with their options based on table column names. But when i select a value, and save the mapping, and then refresh the browser page, all dropdowns goes back to the default state of "Select an option". I have checked the DB, the values are saved correctly. If i dd($schema) i can see the values are correctly hydrated into their appropriate dropdowns, it's just not filled in the view. Anyone got any ideas?
1 replies
FFilament
Created by caweren on 7/19/2023 in #❓┊help
Missing route parameter when editing resource
Hi all! Relatively new to Filament, coming from Nova. I have a Tenant resource that spits out an error message when I try to edit them (Note, edit. Creation/deletion works fine). It has 2 inputs, a name (string) and a license_id (select, integer, refers to id on licenses table) When ever I try to change anything in the resource, be it name or license, then it errors out with the following error message:
Missing required parameter for [Route: filament.resources.tenants.edit] [URI: admin/tenants/{record}/edit] [Missing parameter: record].
Missing required parameter for [Route: filament.resources.tenants.edit] [URI: admin/tenants/{record}/edit] [Missing parameter: record].
Looking through the trace, it seems to come from Livewires SupportBrowserHistory feature> I've Googled around, but all the answers seems to be some of the more "obvious" once (like wrong parameter name in redirect's etc.). I haven't changed anything in the default Filament routing, and all other resources works correctly, it's only this one. The primary key type of Tenant is a string, and not and integer - I don't know if this is relevant, but it's the only differing factor I can find. I'm happy to supply any code you might want to check through, please let me know.
17 replies