F
Filament15mo ago
Ahmad

How to call a function in another service on saving a relationship manager item of one resource?

I have a resource (Product) that has a related entity called Price (via relationship manager). I want to call an external service when a Price is updated, how can I do that? thanks!
7 Replies
blakdronzer
blakdronzer15mo ago
possibly you can look to makehook your code to afterCreate
Ahmad
AhmadOP15mo ago
where should I define afterCreate (in which Class)? the parent (Product page) ?
blakdronzer
blakdronzer15mo ago
in the Create<Resource> like CreateUser / CreateProduct
Ahmad
AhmadOP15mo ago
tried that. Didn't work just to make sure we are on same page. I'm trying to trigger some action when Price is created/edited, not for Product. And because Price is a relation to Product, Filament doesn't create CreatePrice, EditPrice classes etc. Only CreateProduct, EditProduct, etc are created.
gladjanus43
gladjanus4315mo ago
Maybe an observer is what you are looking for? https://laravel.com/docs/10.x/eloquent#observers
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.
cheesegrits
cheesegrits15mo ago
Observers are always a good way to go. Or you could use an after() method on the CreateAction / EditAction on your RM. https://filamentphp.com/docs/3.x/actions/prebuilt-actions/create#lifecycle-hooks
Ahmad
AhmadOP15mo ago
will give it a try. Thanks a lot for your answer!
Want results from more Discord servers?
Add your server