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'])),
]);
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server