Use a custom widget to run a command from the dashboard
Hi all, I'm looking to have the ability to run a command to generate a report for data on the dashboard, however there doesn't seem to be much documentation about how to use custom widgets unless I'm missing something?
The desired functionality is for a user to click on a widget (or a button in the widget) on the dashboard which will run a script (probably a laravel console command) to generate a report and then download the report to the user's machine.
Does anyone know how I might go about doing this? Specifically I'm asking for help RE: the widget / dashboard side of things.
Thanks
Solution:Jump to solution
You should be able to run commands from the livewire side of the widget. Just put a button in it which triggers a function who in place runs the artisan command.
Put this in the button:
```php
wire:click="runCommand" //runCommand is a placeholder for your own function ofcourse...
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
7 Replies
Solution
You should be able to run commands from the livewire side of the widget. Just put a button in it which triggers a function who in place runs the artisan command.
Put this in the button:
https://laravel.com/docs/10.x/artisan
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
so are custom widgets essentially just livewire components? If I wanted to attach a custom URL to one would I put that in the view or the class?
Yes they are, practically all filament elements are.
https://filamentphp.com/docs/3.x/panels/dashboard#custom-widgets
Oh and what do you mean with custom Url for a widget?
Here's what I've got going on atm, my report generating functionality is happening in a controller method which is called by the route that the user is redirected to.
StatusReport.php
status-report.blade.php
The only thing I'd like to do now is add some CSS to the widget, as currently everything looks the same. Would I have to register a custom stylesheet as a filament asset in the AppServiceProvider?
Uhhh If I remember correctly you need to register a custom filament theme, but the last time I did that it was in filament V2. So I'm not sure, but it's somewhere in the docs for sure
Ofcourse use tailwind for that :D