F
Filamentβ€’15mo ago
Xe

Conditional Selectors take too long to load, or fail to load

Hello, I'll be providing the code that I'm using to load a selector based on another one, It's not generating errors, but it doesn't load sometimes, leading the second selection to always be raw,
14 Replies
Xe
XeOPβ€’15mo ago
Forms\Components\Select::make('wilaya')
->options(
Wilaya::all()->pluck('designation', 'id')
)
->required()
->afterStateUpdated(fn(callable $set) => $set('commune', null)),
Forms\Components\Select::make('commune')
->options(
function (callable $get) {
$wilaya = Wilaya::find($get("wilaya"));
if (!$wilaya) {
return [];
}
return $wilaya->commune->pluck('nomCommune', 'id');
}
Forms\Components\Select::make('wilaya')
->options(
Wilaya::all()->pluck('designation', 'id')
)
->required()
->afterStateUpdated(fn(callable $set) => $set('commune', null)),
Forms\Components\Select::make('commune')
->options(
function (callable $get) {
$wilaya = Wilaya::find($get("wilaya"));
if (!$wilaya) {
return [];
}
return $wilaya->commune->pluck('nomCommune', 'id');
}
here is the code second table contains too much rows in the db, defeats 3000
Lara Zeus
Lara Zeusβ€’15mo ago
try adding ->searchable() and ->preload()
Xe
XeOPβ€’15mo ago
WORKED LIKE MAGIC ✨ is there anyway I also make it searchable on another attribuute? of that entity I mean
blakdronzer
blakdronzerβ€’15mo ago
just add it to the option to the child object should work thank you 2 magician @Lara Zeus
Xe
XeOPβ€’15mo ago
how is that?
blakdronzer
blakdronzerβ€’15mo ago
Forms\Components\Select::make('wilaya') ->options( Wilaya::all()->pluck('designation', 'id') ) ->required() ->afterStateUpdated(fn(callable $set) => $set('commune', null)), Forms\Components\Select::make('commune') ->options( function (callable $get) { $wilaya = Wilaya::find($get("wilaya")); if (!$wilaya) { return []; } return $wilaya->commune->pluck('nomCommune', 'id'); } )->searchable() see if thqat works
Xe
XeOPβ€’15mo ago
ahh, so thatt's gonna make it exist twice right?
blakdronzer
blakdronzerβ€’15mo ago
explore and see πŸ™‚
Xe
XeOPβ€’15mo ago
what I meant was: I'm only plucking the nomCommune, which is the name, is there anyway I could make the search include the id, that is in the db but seeing how this is functionning, the logic seems wrong, this returns only names, so yeah,
Lara Zeus
Lara Zeusβ€’15mo ago
pluck('name','id')
Xe
XeOPβ€’15mo ago
works but makes it only for the id, well, I think it's already a weird idea, to search on both, name, or the id if needed
blakdronzer
blakdronzerβ€’15mo ago
Select::make('author_id') ->relationship(name: 'author', titleAttribute: 'name') ->searchable(['name', 'email']) this way you can .. across multiple fields
Xe
XeOPβ€’15mo ago
maybe it's me, but it somehow provoked something like: the search doesn't work I mean it doesn't do what I needed it to do, but also the search became global! which isn't somthI want I'll look it up more later, maybe I just rushed it
Want results from more Discord servers?
Add your server