F
Filament11mo ago
Abi

Table Widget with Group By

I am creating a table widget with a summary of Subscription Information and here is the code for the table
public function table(Table $table): Table
{
return $table
->query(
Subscription::query()
)
->modifyQueryUsing(function ($query) {
$query->selectRaw('stripe_status, count(*) as count')
->groupBy('stripe_status')
->orderBy('count', 'desc');
})
->contentFooter(null)
->columns([
Tables\Columns\TextColumn::make('stripe_status')
->label('Status'),
Tables\Columns\TextColumn::make('count')
->label('Count'),
]);
}
public function table(Table $table): Table
{
return $table
->query(
Subscription::query()
)
->modifyQueryUsing(function ($query) {
$query->selectRaw('stripe_status, count(*) as count')
->groupBy('stripe_status')
->orderBy('count', 'desc');
})
->contentFooter(null)
->columns([
Tables\Columns\TextColumn::make('stripe_status')
->label('Status'),
Tables\Columns\TextColumn::make('count')
->label('Count'),
]);
}
4 Replies
Abi
AbiOP11mo ago
I get the error Filament\Widgets\TableWidget::getTableRecordKey(): Return value must be of type string, null returned any advice on this would be great
Darkavatar23
Darkavatar2311mo ago
can you post the migration ?
Abi
AbiOP11mo ago
GitHub
cashier-stripe/database/migrations/2019_05_03_000002_create_subscri...
Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services. - laravel/cashier-stripe
Alter
Alter4w ago
Add a column with alias like this ->modifyQueryUsing(function ($query) { $query->selectRaw('stripe_status as id, stripe_status, count(*) as count') ->groupBy('stripe_status') ->orderBy('count', 'desc'); })
Want results from more Discord servers?
Add your server