F
Filament14mo 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 .
24 Replies
Jordy
Jordy14mo ago
that is expected as it renders all widgets on the homepage (dashboard)
toeknee
toeknee14mo ago
You can configure the widgets to display the widgets you want with your panel provider and: ->widgets([ //widgetclas ])
Jordy
Jordy14mo ago
think in v3 you can change it in your panelprovider you beat me haha 😉
toeknee
toeknee14mo ago
That's what she said
lodeki
lodekiOP14mo 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
toeknee14mo ago
Ugh, if you do: ->widgets([ ]) do they still render?
lodeki
lodekiOP14mo ago
Yes .
toeknee
toeknee14mo ago
Something isn't right
awcodes
awcodes14mo ago
the other widget is probably being autodiscovered
lodeki
lodekiOP14mo 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
toeknee14mo ago
That'll do it, comment it out
lodeki
lodekiOP14mo ago
Should i do away with this setting?
toeknee
toeknee14mo ago
I believe so, then the widgets defined will be rendered instead.
lodeki
lodekiOP14mo 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
Bellegend14mo 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
lodekiOP14mo 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 Foresttree13mo ago
Running into the same problem, seems to be a bug, or at the very least undocument behavior
slooffmaster
slooffmaster13mo 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
DrByte12mo 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
toeknee12mo 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 🙂
Abuukar
Abuukar3mo ago
i tried all those ways , but still the widget is appearing in the dashboard , so what is correct solution for this error?
toeknee
toeknee3mo ago
Please open a new post.
Abuukar
Abuukar3mo ago
ok
Want results from more Discord servers?
Add your server