F
Filamentβ€’16mo ago
Kleis

Beta 22 seems to break TableWidget

Anyone else stumped on this ? A fairly simple tableWidget stopped working at beta22 with the error "Typed property Filament\Widgets\TableWidget::$table must not be accessed before initialization"
<?php

namespace App\Filament\Widgets;

use Closure;
use Filament\Tables;
use Filament\Widgets\TableWidget as BaseWidget;
use Illuminate\Database\Eloquent\Builder;

class OpenOrders extends BaseWidget
{
protected static ?int $sort = 10;

protected function getTableQuery(): Builder
{
return \App\Models\Order::where("status_id", 2)->orderBy('id', 'desc');
}

protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('id')->label('#'),
Tables\Columns\TextColumn::make('full_name')->label(__('Name')),
];
}
}
<?php

namespace App\Filament\Widgets;

use Closure;
use Filament\Tables;
use Filament\Widgets\TableWidget as BaseWidget;
use Illuminate\Database\Eloquent\Builder;

class OpenOrders extends BaseWidget
{
protected static ?int $sort = 10;

protected function getTableQuery(): Builder
{
return \App\Models\Order::where("status_id", 2)->orderBy('id', 'desc');
}

protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('id')->label('#'),
Tables\Columns\TextColumn::make('full_name')->label(__('Name')),
];
}
}
Solution:
Use the table() method to configure the table widget. ```php public function table(Table $table): Table {...
Jump to solution
2 Replies
Solution
sumardi
sumardiβ€’16mo ago
Use the table() method to configure the table widget.
public function table(Table $table): Table
{
return $table
->query(\App\Models\Order::where("status_id", 2)->orderBy('id', 'desc'))
->columns([
Tables\Columns\TextColumn::make('id')->label('#'),
Tables\Columns\TextColumn::make('full_name')->label(__('Name')),
])
->filters([
// ...
])
->actions([
// ...
])
->bulkActions([
// ...
]);
}
public function table(Table $table): Table
{
return $table
->query(\App\Models\Order::where("status_id", 2)->orderBy('id', 'desc'))
->columns([
Tables\Columns\TextColumn::make('id')->label('#'),
Tables\Columns\TextColumn::make('full_name')->label(__('Name')),
])
->filters([
// ...
])
->actions([
// ...
])
->bulkActions([
// ...
]);
}
Kleis
KleisOPβ€’16mo ago
thanks πŸ‘
Want results from more Discord servers?
Add your server