SelectFilter with relationship query

I have used SelectFilter and applying query like this but not getting selected value $acd_id inside where. SelectFilter::make('academic_id')->label('Academic Year')->options(fn (Get $get): array => AcademicYear::all()->where('status' , 1)->pluck('month_label', 'id')->all() ) ->query(function (Builder $query, array $data): Builder {
return $query ->when( $data['value'], fn (Builder $query, $acd_id): Builder =>
$query->with('academic') ->whereHas('academic', function ( Builder $query, $acd_id ) { $query->where('academic_id','=', $acd_id ); }) ); })
Solution:
try ->whereHas('academic', function(Builder $query) use ($acd_id) {
Jump to solution
7 Replies
BlackShadow
BlackShadow6mo ago
Check the output of $data first.
Rinkesh
RinkeshOP6mo ago
$data is coming like $data['value'] = '' or $data['value']='3'
BlackShadow
BlackShadow6mo ago
So what happends when you dd the $acd_id in the closure.
Rinkesh
RinkeshOP6mo ago
I a getting error when I use $acd_id
Rinkesh
RinkeshOP6mo ago
Undefined variable $acd_id
No description
Solution
BlackShadow
BlackShadow6mo ago
try ->whereHas('academic', function(Builder $query) use ($acd_id) {
Rinkesh
RinkeshOP6mo ago
Yes it works Thanks
Want results from more Discord servers?
Add your server