FilamentF
Filament14mo ago
Panda

Changing widget column span at runtime?

Hello everyone. I want to show Google Analytics stats in my Filament panel and for that I'm using bezhansalleh-google-analytics plugin which provides multiple widgets for viewing GA data. Now I want to change the width of a widget and for that I tried to create a custom widget and extend the original class but it dosen't work that way so now I want to change the column span of the widget in widgets array of the page. The issue is that we need to specify the widgets using class-string syntax and not by initialising the instance.

<?php

class GoogleAnalytics extends Page
{
    protected function getHeaderWidgets(): array
    {
        return [
            // I want to make these widgets span 2 columns
            \BezhanSalleh\FilamentGoogleAnalytics\Widgets\PageViewsWidget::class,
            \BezhanSalleh\FilamentGoogleAnalytics\Widgets\VisitorsWidget::class,
            \BezhanSalleh\FilamentGoogleAnalytics\Widgets\ActiveUsersOneDayWidget::class,

            // I want to make these widgets span 3 columns
            \BezhanSalleh\FilamentGoogleAnalytics\Widgets\SessionsByCountryWidget::class,
            \BezhanSalleh\FilamentGoogleAnalytics\Widgets\SessionsByDeviceWidget::class,

            // I want to make these widgets take full width
            \BezhanSalleh\FilamentGoogleAnalytics\Widgets\MostVisitedPagesWidget::class,
            \BezhanSalleh\FilamentGoogleAnalytics\Widgets\TopReferrersListWidget::class,
        ];
    }

    public function getHeaderWidgetsColumns(): int | array
    {
        return [
            'xl' => 6,
        ];
    }
}
Filament
Filament support for Spatie's Laravel Analytics package.
Was this page helpful?