F
Filamentβ€’16mo ago
Ninja++

How to add widgets to default dashboard page.

Hi I am a little confused about how to add the widgets i have created to the defualt page that comes with the admin pannel. I am struggling to understand were it is defined in the file structure at all. I have made widgets and can add them to other pages i have created but not been able so far to add this to the defult page. Thanks in advance
37 Replies
Jordy
Jordyβ€’16mo ago
Your dashboard page is defined in your filament config file
Ninja++
Ninja++OPβ€’16mo ago
So if i define the class of the widget in this list it will show up on the dashboard page?
Jordy
Jordyβ€’16mo ago
No, go to the dashboard page that is registered for you
Ninja++
Ninja++OPβ€’16mo ago
That is why i am confused becuase the pages directory is empty
awcodes
awcodesβ€’16mo ago
Any widgets in App\Filament\Widgets will show up on the dashboard automatically. If you widget isn’t in that directory you would add it to the register array there.
Jordy
Jordyβ€’16mo ago
It's not there, the default one is in your vendor.. It's defined in your config file.. That's why I told you to go there It has a widgets function and shows all widget by default but you can overwrite it to your own dashboard page and define yourself what widgets to show.. If your widget is not show automatically it is either Not in the App\Filament\Widgets namespace (likely) Or you already have a custom dashboard page where you defined what widgets to show (unlikely)
Ninja++
Ninja++OPβ€’16mo ago
I really do not understand this reply im sorry, I am more consfued the more times i have read it
Jordy
Jordyβ€’16mo ago
Your dashboard page is defined here. You can check what widgets are showing by going to it's location However the default behavior should be to show all the widgets you have (as long they are in the right namespace)
Ninja++
Ninja++OPβ€’16mo ago
I created the widget following the steps in the docs, i specified a resource when i ran the command and then i added this to the parent resource
Jordy
Jordyβ€’16mo ago
Yeah
Ninja++
Ninja++OPβ€’16mo ago
Right so my widget must be defined in the name space wrong?
Jordy
Jordyβ€’16mo ago
It's not in App\Filament\Widgets It is in MaterialResource\Widgets\
Ninja++
Ninja++OPβ€’16mo ago
Ninja++
Ninja++OPβ€’16mo ago
when i ran the command that is where it put it
Jordy
Jordyβ€’16mo ago
Yes πŸ˜‚
Ninja++
Ninja++OPβ€’16mo ago
php artisan make:filament-widget MaterialsWidget --resource=MaterialsResource
php artisan make:filament-widget MaterialsWidget --resource=MaterialsResource
`
Jordy
Jordyβ€’16mo ago
But if you want it to show you would have to put it in App\Filament\Widgets or make a custom dashboard class Or register it here
Ninja++
Ninja++OPβ€’16mo ago
Right i am hoping to make the dashbord contents change depending on user type so what do you suggest is the best way to proceed? Make a new custom dashboard type? When i put the class there it did not show up
Jordy
Jordyβ€’16mo ago
Then make a custom page called dashboard And define it here.. It should replace the default dashboard
Ninja++
Ninja++OPβ€’16mo ago
When i declare like this it does not find the class
Jordy
Jordyβ€’16mo ago
Well you are going to import it I don't know your ide but I would just delete everything before MaterialWidget::class, hover over and press import πŸ˜‚
Ninja++
Ninja++OPβ€’16mo ago
Like this?
Jordy
Jordyβ€’16mo ago
does it work?
Ninja++
Ninja++OPβ€’16mo ago
Ninja++
Ninja++OPβ€’16mo ago
no
Jordy
Jordyβ€’16mo ago
Yes
Ninja++
Ninja++OPβ€’16mo ago
it says it cant find the class
Jordy
Jordyβ€’16mo ago
Delete Widgets\ Just the name should do
Ninja++
Ninja++OPβ€’16mo ago
ok it did when i clicked another part of the line
Jordy
Jordyβ€’16mo ago
πŸ‘Should work now then
Ninja++
Ninja++OPβ€’16mo ago
Sadnly no
Ninja++
Ninja++OPβ€’16mo ago
This is what the card looks like
Jordy
Jordyβ€’16mo ago
It does work.. You just have an error inside your widget πŸ˜‰ <x-filament::card> Not x-filament-card
Ninja++
Ninja++OPβ€’16mo ago
ok that worked, now I just need to sort out this user count variable, which i think i have to define the pick in the pairent resoruce?
Jordy
Jordyβ€’16mo ago
Play around with it.. You learn best by doing.. And failing πŸ˜…πŸ˜‚
Ninja++
Ninja++OPβ€’16mo ago
Thank you for your help, I had to abandon the other tech stack i was using and i have literally a week to learn and publish this project So i am stressing just a lil bit not like my entire degree is on the line.....
Jordy
Jordyβ€’16mo ago
keep calm, it is the only way to think straight.. good luck
Want results from more Discord servers?
Add your server