Dependency injection.

How can i inject a service in filament ? i try method construct but it makes error
8 Replies
Dennis Koch
Dennis Koch17mo ago
Dependencies are injected in mount() in Livewire components. You can also use app() to resolve them from the container.
Patrick Boivin
Patrick Boivin17mo ago
Depends on what you're trying to do... Use mount() if the service is only needed once when the page is initialized or use boot() if the service is needed for every subsequent request/action.
Dan Harrin
Dan Harrin17mo ago
where do you actually need the service
Messenger of truth
Messenger of truthOP17mo ago
i have a button named export in list screen. When user click it. I export a file for user. So i think i must inject service in ListRecords. Do I think that's right?
Dan Harrin
Dan Harrin17mo ago
you have an Action?
Messenger of truth
Messenger of truthOP17mo ago
Yes, i have an action for user export and download file
Dan Harrin
Dan Harrin17mo ago
->action(fn (YourServiceHere $service) => ...) you can inject in that function
Messenger of truth
Messenger of truthOP17mo ago
Ok, Let me try. Filament is great. Let's keep developing it
Want results from more Discord servers?
Add your server