Reactive filter updating

So on my custom page, where I have a filtersForm. Its generated with:
public function filtersForm(Form $form): Form
{
return $form->schema([
Forms\Components\Section::make('Filters')
->schema([
Forms\Components\Grid::make(4)
->schema([
Forms\Components\Select::make('client')
->label('Client')
->placeholder('Select a client')
->options($this->getClientOptions())
->default(''),

Forms\Components\Select::make('project')
->label('Project')
->placeholder('Search for a project')
->options($this->getProjectOptions())
->default(''),
])
])
->collapsed()
->persistCollapsed(),
]);
}

/**
* Client filter dropdown
*
* @return array
*/
protected function getClientOptions(): array
{
$client = \App\Models\Client::query();

if (empty($this->filters['client'])) {
$this->filters['project'] = null;
}

return $client->pluck('name', 'id')->toArray();
}

protected function getProjectOptions()
{
$project = \App\Models\Project::query();

if (!empty($this->filters['client'])) {
$project->where('client_id', $this->filters['client']);
}

return $project->pluck('name', 'id')->toArray();
}
public function filtersForm(Form $form): Form
{
return $form->schema([
Forms\Components\Section::make('Filters')
->schema([
Forms\Components\Grid::make(4)
->schema([
Forms\Components\Select::make('client')
->label('Client')
->placeholder('Select a client')
->options($this->getClientOptions())
->default(''),

Forms\Components\Select::make('project')
->label('Project')
->placeholder('Search for a project')
->options($this->getProjectOptions())
->default(''),
])
])
->collapsed()
->persistCollapsed(),
]);
}

/**
* Client filter dropdown
*
* @return array
*/
protected function getClientOptions(): array
{
$client = \App\Models\Client::query();

if (empty($this->filters['client'])) {
$this->filters['project'] = null;
}

return $client->pluck('name', 'id')->toArray();
}

protected function getProjectOptions()
{
$project = \App\Models\Project::query();

if (!empty($this->filters['client'])) {
$project->where('client_id', $this->filters['client']);
}

return $project->pluck('name', 'id')->toArray();
}
I want project to update live with my data when client changes. So for example, I select client 1, and select project 1 (as that belongs to client 1). If I then change to Client 2, I need Project 1 to reset when it changes, so I can also populate the infolist live, being returned.
4 Replies
Jamie Cee
Jamie CeeOP5mo ago
For clarification, the input dropdown does update, but the filter queries dont
LeandroFerreira
LeandroFerreira5mo ago
Select::make('project')
...
->options(fn (Get $get) => Project::whereClientId($get('client'))->pluck('name', 'id'))
Select::make('project')
...
->options(fn (Get $get) => Project::whereClientId($get('client'))->pluck('name', 'id'))
Jamie Cee
Jamie CeeOP5mo ago
Thats still seeming to not update the body? as the project in my query is still the one from another client...
CORONEL
CORONEL5mo ago
->live() on the 'client' select?
Want results from more Discord servers?
Add your server