Select Field Component State: Injecting Title along with ID

Hey all, Wondering if this is possible at all without formatting the state with ->formatStateUsing() I'm trying to fetch an ID from a request, which will subsequently inject the ID in the request into the Select Component. It's working, I have the correct ID, but I'm wondering if something like this is possbile:
->afterStateHydrated(function (Request $request, Select $component) {
$request = $request->all();
if (isset($request['page_id'])) {
$toplist = Toplist::scopeToplistByPageId($request['page_id'])->toArray();
$component->state([$toplist['id'],$toplist['title']]);
}
})
->afterStateHydrated(function (Request $request, Select $component) {
$request = $request->all();
if (isset($request['page_id'])) {
$toplist = Toplist::scopeToplistByPageId($request['page_id'])->toArray();
$component->state([$toplist['id'],$toplist['title']]);
}
})
Especially this line $component->state([$toplist['id'],$toplist['title']]); I don't think it's possible? I've also tried other variants like $component->state(['id' => $toplist['id'],'title' => $toplist['title']]); Anyone have any suggestions or should I just use formatStateUsing()?
1 Reply
Ramon.vV
Ramon.vVOP9mo ago
Okay apparently I hadn't setup my relation properly for the select and that takes care of the title automatically. Still wondering if something like this is possible though?
Want results from more Discord servers?
Add your server