Ifeoluwa
Ifeoluwa
FFilament
Created by Ifeoluwa on 1/31/2024 in #❓┊help
Access other form elements in modifyQueryUsing of NumberConstraint
Hello everyone, So I have a $table in a RelationManager with a filter
->filters([
QueryBuilder::make()
->constraints([
SelectConstraint::make('gender')->icon('heroicon-m-book-open')->icon('heroicon-m-user')
->options([
'male' => 'Male',
'female' => 'Female',
]),
DateConstraint::make('completions.auxilliary_date')->label('Completion Date')->icon('heroicon-m-calendar-days'),
NumberConstraint::make('completion.courses_cummulative')->label('Courses Completed')->integer()->icon('heroicon-m-book-open')
->relationship(
name: 'completion',
titleAttribute: 'courses_cummulative',
modifyQueryUsing: fn (Builder $query, $data) => $query->whereNotIn('completion.learner_id',
fn (Builder $query, $data) => $query->select('a.learner_id')->from('completion_auxilliary as a')
->where('a.auxilliary_date', '<', $data['completions.auxilliary_date'] )
->where('a.courses_cummulative', '>=', $data['completion.courses_cummulative'] )
),
),
]),

], layout: FiltersLayout::AboveContent)
->filters([
QueryBuilder::make()
->constraints([
SelectConstraint::make('gender')->icon('heroicon-m-book-open')->icon('heroicon-m-user')
->options([
'male' => 'Male',
'female' => 'Female',
]),
DateConstraint::make('completions.auxilliary_date')->label('Completion Date')->icon('heroicon-m-calendar-days'),
NumberConstraint::make('completion.courses_cummulative')->label('Courses Completed')->integer()->icon('heroicon-m-book-open')
->relationship(
name: 'completion',
titleAttribute: 'courses_cummulative',
modifyQueryUsing: fn (Builder $query, $data) => $query->whereNotIn('completion.learner_id',
fn (Builder $query, $data) => $query->select('a.learner_id')->from('completion_auxilliary as a')
->where('a.auxilliary_date', '<', $data['completions.auxilliary_date'] )
->where('a.courses_cummulative', '>=', $data['completion.courses_cummulative'] )
),
),
]),

], layout: FiltersLayout::AboveContent)
So how do I access the fields in the earlier QueryBuilder constraints and use them inside the modifyQueryUsing of the final constraint? I tried using $data in the closure I got an error: An attempt was made to evaluate a closure for [Filament\Tables\Filters\QueryBuilder\Constraints\NumberConstraint\Operators\IsMinOperator], but [$data] was unresolvable. Thank you so much
2 replies