How to custom filament v3 widget table? I have this data from cache
$dashboardData = new DashboardData();
$data = $dashboardData->retrieve();
$todayData = $data->get('most_sold_series');
how to pass the in the query? or should I change the whole structure?
public function table(Table $table): Table
{
return $table
->query(
// ...
)
->columns([
// ...
]);
}
use Filament\Tables\Table;
use Illuminate\Support\Collection;
use Filament\Tables\Columns\TextColumn;
public function table(Table $table): Table
{
// Fetch cached data
$dashboardData = new DashboardData();
$data = $dashboardData->retrieve();
// Convert cached data to collection
$todayData = collect($data->get('most_sold_series'));
return $table
->query(fn () => $todayData) // Use collection as query source
->columns([
]);
}
@iamjohndev
I tried already but not working sir, I got error Method Illuminate\Support\Collection::clone does not exist.
<?php
namespace App\Filament\Widgets;
use Filament\Tables;
use Filament\Tables\Table;
use App\Services\Dashboard\DashboardData;
use Filament\Widgets\TableWidget as BaseWidget;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
class SampleTable extends BaseWidget
{
use InteractsWithPageFilters;
protected static ?string $heading = 'Most Watched Movies';
protected static ?int $sort = 10;
public function table(Table $table): Table
{
// Retrieve the cached data
$dashboardData = new DashboardData();
$todayData = $dashboardData->retrieve();
// Get the cached most_sold_movies data
$mostSoldTitles = $todayData->get('most_sold_movies', collect());
\Log::info("Data", ['data from cache' => $mostSoldTitles]);
return $table
->query(fn () => $mostSoldTitles)
->columns([
Tables\Columns\TextColumn::make('title')
->label('Movies Title')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('total_amount')
->label('Total Amount')
->sortable()
->getStateUsing(fn ($record) => number_format($record['total_amount'], 2)),
]);
}
}
Please sign in or create an account to participate in this conversation.