F
Filament9mo ago
lodeki

Page widget showing on dashboard

Had a quick one. I created a page using
bash php artisan make:filament-page Settings
bash php artisan make:filament-page Settings
and created a widget. I added the widget to the
getHeaderWidgets()
getHeaderWidgets()
of the page .However the widget is also showing on the dashboard .
21 Replies
Jordy
Jordy9mo ago
that is expected as it renders all widgets on the homepage (dashboard)
toeknee
toeknee9mo ago
You can configure the widgets to display the widgets you want with your panel provider and: ->widgets([ //widgetclas ])
Jordy
Jordy9mo ago
think in v3 you can change it in your panelprovider you beat me haha 😉
toeknee
toeknee9mo ago
That's what she said
lodeki
lodeki9mo ago
Tried it out by listing
->widgets([
ApexChart::class,
StatsOverview::class
])
->widgets([
ApexChart::class,
StatsOverview::class
])
the widgets excluding the one i don't want on the dashboard but still the other widget appears .
toeknee
toeknee9mo ago
Ugh, if you do: ->widgets([ ]) do they still render?
lodeki
lodeki9mo ago
Yes .
toeknee
toeknee9mo ago
Something isn't right
awcodes
awcodes9mo ago
the other widget is probably being autodiscovered
lodeki
lodeki9mo ago
Makes sense ..Actually i have this line
->discoverWidgets(in: app_path('Filament/Manager/Widgets'), for: 'App\\Filament\\Manager\\Widgets')
->discoverWidgets(in: app_path('Filament/Manager/Widgets'), for: 'App\\Filament\\Manager\\Widgets')
in the provider .
toeknee
toeknee9mo ago
That'll do it, comment it out
lodeki
lodeki9mo ago
Should i do away with this setting?
toeknee
toeknee9mo ago
I believe so, then the widgets defined will be rendered instead.
lodeki
lodeki9mo ago
Atleast there is progress .The widget no longer shows on the dashboard .However , checking it out on the intended page throws
Unable to find component: [app.filament.manager.widgets.x-widget]
Unable to find component: [app.filament.manager.widgets.x-widget]
.
Bellegend
Bellegend9mo ago
Happened to me same problem https://discord.com/channels/883083792112300104/1160981510850093096 Check my post I'm interested if you find a solution I got a work around it but not good i need multiple dashboards i found a another way and its working fine now i created custom page for the DocumentRecordResource and a widgets for that custom page as below
php artisan make:filament-page StatsDocumentRecord --resource=Cataloging/DocumentRecordResource --type=custom
php artisan make:filament-widget DocumentRecordsByYearTable --chart --resource=Cataloging/DocumentRecordResource
php artisan make:filament-page StatsDocumentRecord --resource=Cataloging/DocumentRecordResource --type=custom
php artisan make:filament-widget DocumentRecordsByYearTable --chart --resource=Cataloging/DocumentRecordResource
and i added a navigation to that custom page in the AdminServiceProvider like this
->navigationItems([
NavigationItem::make('Analytics')
->label(fn () => __('panel.pages.DocumentStatistics'))
->url(fn (): string => StatsDocumentRecord::getUrl())
->icon('heroicon-o-presentation-chart-line')
->group(fn () => __('panel.groups.statistics'))
->sort(0),
])
->navigationItems([
NavigationItem::make('Analytics')
->label(fn () => __('panel.pages.DocumentStatistics'))
->url(fn (): string => StatsDocumentRecord::getUrl())
->icon('heroicon-o-presentation-chart-line')
->group(fn () => __('panel.groups.statistics'))
->sort(0),
])
hope this help someone but the other way i think it has a bug
lodeki
lodeki9mo ago
I resolved it by overriding the function
public function getWidgets(): array
{
return [
//my widgets
];
}
public function getWidgets(): array
{
return [
//my widgets
];
}
on the dashboard page .
Pete Foresttree
Pete Foresttree8mo ago
Running into the same problem, seems to be a bug, or at the very least undocument behavior
slooffmaster
slooffmaster8mo ago
Workaround is to do something like this in the Widget:
/**
* Determine where the widget should be displayed
*
* @see https://filamentphp.com/docs/3.x/panels/dashboard#conditionally-hiding-widgets
* @return bool
*/
public static function canView(): bool
{
if (Route::currentRouteName() === 'filament.admin.pages.sales-dashboard') {
return true;
}

return false;
}
/**
* Determine where the widget should be displayed
*
* @see https://filamentphp.com/docs/3.x/panels/dashboard#conditionally-hiding-widgets
* @return bool
*/
public static function canView(): bool
{
if (Route::currentRouteName() === 'filament.admin.pages.sales-dashboard') {
return true;
}

return false;
}
DrByte
DrByte8mo ago
Another (related) approach: I have a situation where I have multiple dashboards on one Panel. So, I grouped my widgets in subdirectories and let the Panel autodiscover them (it traverses the subdirs). Then in each dashboard I declared getWidgets() like this:
public function getWidgets(): array
{
return collect(parent::getWidgets())
->filter(fn ($value):bool => strpos($value, '\Tech\\'))
->toArray();
}
public function getWidgets(): array
{
return collect(parent::getWidgets())
->filter(fn ($value):bool => strpos($value, '\Tech\\'))
->toArray();
}
(in my case \Tech\ was the namespace/subdir for one of the dashboards' widgets)
toeknee
toeknee8mo ago
That's one way of doing it, you could also put them in the canView and if the user has the tenant. I suspect your approach will be less resource intensive 🙂