© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
1 reply
nathan269_

How To Call Service To Retrieve Data Within Table Widget?

Hi folks,

how can i retrieve data from a service I have setup, from within the table widget? I previously used the ->query method because I just reference data from within my database, however, i no longer save the data anymore. This is my code:

private PlausibleAnalyticsService $plausibleAnalyticsService;

    public function __construct()
    {
        $this->plausibleAnalyticsService = new PlausibleAnalyticsService();
    }

    protected function getData(): array
    {
        return $this->plausibleAnalyticsService->fetchTopPages();
    }

    public function table(Tables\Table $table): Tables\Table
    {
        return $table
            // set data from fetchTopPages() method
            ->columns([
                TextColumn::make('page')
                    ->label('Page')
                    ->getStateUsing(fn ($record) => $record['page']),
                TextColumn::make('visitors')
                    ->label('Visitors')
                    ->getStateUsing(fn ($record) => number_format($record['visitors'])),
                TextColumn::make('pageviews')
                    ->label('Page Views')
                    ->getStateUsing(fn ($record) => number_format($record['pageviews'])),
            ]);
    }
private PlausibleAnalyticsService $plausibleAnalyticsService;

    public function __construct()
    {
        $this->plausibleAnalyticsService = new PlausibleAnalyticsService();
    }

    protected function getData(): array
    {
        return $this->plausibleAnalyticsService->fetchTopPages();
    }

    public function table(Tables\Table $table): Tables\Table
    {
        return $table
            // set data from fetchTopPages() method
            ->columns([
                TextColumn::make('page')
                    ->label('Page')
                    ->getStateUsing(fn ($record) => $record['page']),
                TextColumn::make('visitors')
                    ->label('Visitors')
                    ->getStateUsing(fn ($record) => number_format($record['visitors'])),
                TextColumn::make('pageviews')
                    ->label('Page Views')
                    ->getStateUsing(fn ($record) => number_format($record['pageviews'])),
            ]);
    }
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

consume data from service class to widget table
FilamentFFilament / ❓┊help
2y ago
Table data in widget
FilamentFFilament / ❓┊help
2y ago
Using Table within a custom widget
FilamentFFilament / ❓┊help
3y ago
How to pass data from cache to widget table?
FilamentFFilament / ❓┊help
13mo ago