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:Jump to solution
Solved.
Solution:
`
->query(Project::query())
->modifyQueryUsing(fn(Builder $query) => $query->where('project_date','>=', now())->take(7))...
1 Reply
Solution
Solved.
Solution:
->query(Project::query())
->modifyQueryUsing(fn(Builder $query) => $query->where('project_date','>=', now())->take(7))