Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

earmsby's avatar

problem adding widget to resource

I can't figure out the source of an error I am getting when attempting to add a widget to a resource page. I think I've followed the example given in the filament docs (https://filamentphp.com/docs/4.x/resources/widgets) as closely as possible.

Here is the relevant code on the resource:

namespace App\Filament\Resources\Publications;
use App\Filament\Resources\Publications\Pages\ListPublications;
use App\Filament\Resources\Publications\Widgets\SalesOverview;
\\ etc. 

public static function getWidgets(): array
    {
        return [
            SalesOverview::class,
        ];
    }

Here is the widget code:

namespace App\Filament\Resources\Publications\Widgets;

use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;

class SalesOverview extends StatsOverviewWidget
{
    protected function getStats(): array
    {
        return [
            Stat::make('All Time Sales', '$10,000.00'),
            Stat::make('This Year Sales', '$100.00'),
        ];
    }
}

And in the ViewPublication page (the resource page where I want to show the widget) I have:

namespace App\Filament\Resources\Publications\Pages;

use App\Filament\Resources\Publications\PublicationResource;
use Filament\Actions\EditAction;
use Filament\Resources\Pages\ViewRecord;

class ViewPublication extends ViewRecord
{
    protected static string $resource = PublicationResource::class;

    protected function getFooterWidgets(): array
    {
        return [
            PublicationResource\Widgets\SalesOverview::class,
        ];
    }

The error that is thrown is: Class "App\Filament\Resources\Publications\PublicationResource\Widgets\SalesOverview" not found

I suspect the issue is in the line in the getFooterWidgets() function:

PublicationResource\Widgets\SalesOverview::class,

But, again, that's pretty much exactly what the docs show (except with Customer instead of Publication).

FWIW, changing "PublicationResource\Widgets\SalesOverview::class," to "Publications\Widgets\SalesOverview::class," just gives a slightly different not found error.

Any suggestions?

0 likes
2 replies
LaryAI's avatar
Level 58

Certainly! The error message:

Class "App\Filament\Resources\Publications\PublicationResource\Widgets\SalesOverview" not found

…means PHP is looking for the SalesOverview widget inside the namespace:

App\Filament\Resources\Publications\PublicationResource\Widgets

However, based on your code, the widget is actually located here:

App\Filament\Resources\Publications\Widgets\SalesOverview

Solution

In your ViewPublication page, you must reference the correct namespace for SalesOverview. You have two options:

1. Add a use statement

At the top of your ViewPublication file, add:

use App\Filament\Resources\Publications\Widgets\SalesOverview;

Then, update your getFooterWidgets method like this:

protected function getFooterWidgets(): array
{
    return [
        SalesOverview::class,
    ];
}

2. Use the fully-qualified class name directly

If you prefer not to use a use statement, specify the full class path:

protected function getFooterWidgets(): array
{
    return [
        \App\Filament\Resources\Publications\Widgets\SalesOverview::class,
    ];
}

Recap

The issue is namespace reference:
You should reference Widgets\SalesOverview, not PublicationResource\Widgets\SalesOverview.


Bonus tip:
The Filament docs (with “CustomerResource\Widgets\SomeWidget”) assume Widgets lives under your Resource class, but you put your widgets as a sibling to the Resource class. So always double-check the exact namespace and directory organization for your widgets.

Let me know if you need help with something else!

earmsby's avatar

For posterity, adding use App\Filament\Resources\Publications\Widgets\SalesOverview; to the viewPublication file solved the problem.

Please or to participate in this conversation.