F
Filament5mo ago
Felix

costom table widget query is empty

I am trying to have an table with all upcoming projects that I have, but when there are no project coming it gives an Unable to create query for empty collection. . the code is public function table(Table $table): Table { return $table ->query( function () { return Project::where('project_date','>=', now())->get()->sortBy('project_date')->take(7)->ToQuery(); } ) ->columns([ Tables\Columns\TextColumn::make('name'), Tables\Columns\TextColumn::make('project_date'), ]) ->defaultSort('project_date') ->actions([ Tables\Actions\EditAction::make() ->url(fn (Project $record): string => route('filament.admin.resources.projects.edit', ['record' => $record])) ]) ->emptyStateHeading('No upcoming projects') ->paginated(false); } I am rather new with widgets and I haven't worked with ->query before.
Solution:
Solved. Solution: ` ->query(Project::query()) ->modifyQueryUsing(fn(Builder $query) => $query->where('project_date','>=', now())->take(7))...
Jump to solution
1 Reply
Solution
Felix
Felix5mo ago
Solved. Solution: ->query(Project::query()) ->modifyQueryUsing(fn(Builder $query) => $query->where('project_date','>=', now())->take(7))