Reactive filter updating
So on my custom page, where I have a filtersForm.
Its generated with:
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.
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.