Where exactly (file/class/method/row) this error happens?
Getting Cannot use "::class" on null
I'm using FilamentPHP and have a resource with two tabs: "transactions" and "balances". The "transactions" tab works fine, but when I switch to the "balances" tab, I get the error:
Cannot use "::class" on null
namespace App\Filament\Resources\Operations\CollectionNetworkTransactionResource\Pages;
use App\Filament\Resources\Operations\CollectionNetworkTransactionResource; use Brick\Math\BigRational; use Filament\Actions; use Filament\Resources\Components\Tab; use Filament\Resources\Pages\ListRecords; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Columns\Summarizers\Sum; use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder;
class ListCollectionNetworkTransaction extends ListRecords { protected static string $resource = CollectionNetworkTransactionResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
public function getTabs(): array
{
return [
'balances' => Tab::make(__('Balances'))
->icon('heroicon-o-chart-bar')
->query(fn (Builder $query) => $query),
'transactions' => Tab::make(__('Transactions'))
->icon('heroicon-o-chart-bar')
->query(fn (Builder $query) => $query->whereIn('type', ['cash_in', 'cash_out'])),
];
}
public function updatedActiveTab(): void
{
$this->resetTable();
}
public function table(Table $table): Table
{
if ($this->activeTab === 'transactions') {
return $table
->columns([
TextColumn::make('id')->label('#'),
TextColumn::make('paymentMethod.name')
->label(__('Payment Method'))
->searchable(),
TextColumn::make('description')
->label(__('Description'))
->limit(50)
->searchable(),
TextColumn::make('currency.code')
->label(__('Currency'))
->searchable(),
TextColumn::make('type')
->label(__('Operation'))
->searchable()
->badge(),
TextColumn::make('amount')
->label(__('Amount'))
->formatStateUsing(function ($state) {
if ($state instanceof BigRational) {
$state = $state->toFloat();
} elseif (is_string($state) && str_contains($state, '/')) {
[$num, $den] = explode('/', $state);
if ($den != 0) {
$state = (float) $num / (float) $den;
}
}
$formatted = rtrim(rtrim(number_format($state, 8, '.', ''), '0'), '.');
return $formatted ?: '0';
}),
]);
}
return $table
->query(fn (Builder $query) =>
$query->select([
'payment_method_id',
'type',
'currency_id',
\DB::raw('SUM(amount) as total_amount'),
])
->groupBy('payment_method_id', 'type', 'currency_id')
->with(['paymentMethod', 'currency']) // eager load para evitar N+1
)
->columns([
TextColumn::make('paymentMethod.name')
->label(__('Payment Method')),
TextColumn::make('type')
->label(__('Type')),
TextColumn::make('currency.code')
->label(__('Currency')),
TextColumn::make('total_amount')
->label(__('Total Amount'))
->formatStateUsing(fn($state) => rtrim(rtrim(number_format((float) $state, 8, '.', ''), '0'), '.')),
]);
}
}
The namespaces in this file and the resource are correct. The "transactions" tab works perfectly. The error only appears when I switch to the "balances" tab, which uses a grouped/summed query.
I want to display grouped and summed transactions by currency, payment method, and type in the "balances" tab.
Please or to participate in this conversation.