© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
3 replies
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.
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);
}
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))

->query(Project::query())
->modifyQueryUsing(fn(Builder $query) => $query->where('project_date','>=', now())->take(7))
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Widget table custom query
FilamentFFilament / ❓┊help
2y ago
Error table query for table widget
FilamentFFilament / ❓┊help
3y ago
Empty state on Dashboard Table Widget
FilamentFFilament / ❓┊help
2y ago
Table Widget - query with join
FilamentFFilament / ❓┊help
16mo ago