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();
}