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
possibly you can look to makehook your code to afterCreate
where should I define afterCreate (in which Class)? the parent (Product page) ?
in the Create<Resource>
like CreateUser / CreateProduct
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.
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.
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
will give it a try. Thanks a lot for your answer!