Custom Filter Indicator removal to affect multiple fields removal

Hi, i have custom Filter with 3 fields related each other or dependent. From the filter drop down menu, if I am using field #1 and field #2, then remove #1, the other lower fields successfully resetting like what I intended. But, if I remove the filter from indicator, the lower field's filter persist and the table's data list not reset.
->query(function(Builder $query, array $data): Builder {
return $query
->when(
$data['Curriculum'],
fn (Builder $query, $value) => $query->whereHas('grade.level', fn($query) => $query->where('curriculum_id', $value))
)
->when(
$data['Level'],
fn (Builder $query, $value) => $query->whereHas('grade', fn($query) => $query->where('level_id', $value))
)
->when(
$data['Grade'],
fn (Builder $query, $value) => $query->where('grade_id', $value)
);
})
->indicateUsing(function(array $data): array {
if (empty($data)) {
return null;
}
$indicators = [];
if($data['Curriculum']) {
$indicators[] = Indicator::make('Curriculum : ' . Curriculum::find($data['Curriculum'])->name)
->removeField('Curriculum');
if($data['Level']){
$indicators[] = Indicator::make('Level : ' . Level::find($data['Level'])->name)
->removeField('Level');
if($data['Grade']){
$indicators[] = Indicator::make('Grade : ' . Grade::find($data['Grade'])->name)
->removeField('Grade');
}
}
}
return $indicators;;
})
->query(function(Builder $query, array $data): Builder {
return $query
->when(
$data['Curriculum'],
fn (Builder $query, $value) => $query->whereHas('grade.level', fn($query) => $query->where('curriculum_id', $value))
)
->when(
$data['Level'],
fn (Builder $query, $value) => $query->whereHas('grade', fn($query) => $query->where('level_id', $value))
)
->when(
$data['Grade'],
fn (Builder $query, $value) => $query->where('grade_id', $value)
);
})
->indicateUsing(function(array $data): array {
if (empty($data)) {
return null;
}
$indicators = [];
if($data['Curriculum']) {
$indicators[] = Indicator::make('Curriculum : ' . Curriculum::find($data['Curriculum'])->name)
->removeField('Curriculum');
if($data['Level']){
$indicators[] = Indicator::make('Level : ' . Level::find($data['Level'])->name)
->removeField('Level');
if($data['Grade']){
$indicators[] = Indicator::make('Grade : ' . Grade::find($data['Grade'])->name)
->removeField('Grade');
}
}
}
return $indicators;;
})
1 Reply
Dennyvik
DennyvikOP3mo ago
I tried using multiple removeField() like the code below, but it's not working.
$indicators[] = Indicator::make('Curriculum : ' . Curriculum::find($data['Curriculum'])->name)
->removeField('Curriculum')
->removeField('Level');
$indicators[] = Indicator::make('Curriculum : ' . Curriculum::find($data['Curriculum'])->name)
->removeField('Curriculum')
->removeField('Level');
Want results from more Discord servers?
Add your server