F
Filament7mo ago
Rozay

Passing/accessing $get in a custom view

I am probably approaching this wrong, but I think if I can access/pass the $get data then I can solve the problem. I have been using a repeater to handle multiple entries into a rota. I have been asked to look at changing it so the entries are in a table format. Initially, I thought the key/value component would be a good fit, the key would be the day of the week, the value would be the id of the contact. However, I want the user to be able to use a select rather than a free text box. I looked to see if this was possible, but it looked like the most approriate option would be to use a custom view. I've set one up [screenshot 2], but I need the contact selects to be populated based on options selected on the page. I have tried passing the data with the viewData method:
Forms\Components\View::make('forms.components.rota')
->live()
->viewData([
'specialty_id' => fn (Get $get): ?int => $get('specialty_id'),
'grade' => fn (Get $get): ?Model => $get('grade_id') ? Grades::query()
->where('id', $get('grade_id'))
->first() : null,
])
Forms\Components\View::make('forms.components.rota')
->live()
->viewData([
'specialty_id' => fn (Get $get): ?int => $get('specialty_id'),
'grade' => fn (Get $get): ?Model => $get('grade_id') ? Grades::query()
->where('id', $get('grade_id'))
->first() : null,
])
And then in the view:
<x-filament::input.wrapper>
<x-filament::input.select wire:model="contact">
<option value="0" disabled selected>Select a contact</option>
@foreach(\App\Models\Contact::where('specialty_id', $specialty_id)->get() as $contact)
<option value="{{ $contact->id }}">{{ $contact->name }}</option>
@endforeach
</x-filament::input.select>
</x-filament::input.wrapper>
<x-filament::input.wrapper>
<x-filament::input.select wire:model="contact">
<option value="0" disabled selected>Select a contact</option>
@foreach(\App\Models\Contact::where('specialty_id', $specialty_id)->get() as $contact)
<option value="{{ $contact->id }}">{{ $contact->name }}</option>
@endforeach
</x-filament::input.select>
</x-filament::input.wrapper>
Any help would be appreciated. I'm sure there's a simple solution to this!
No description
No description
0 Replies
No replies yetBe the first to reply to this messageJoin