F
Filament2mo ago
AgonK

how to send request and get response inside action button

Im trying to send get/post request inside action ( button in header section). I tried with route and Http::post(route(name,params) but nothing works. How can I send request and get response, and based on response show the notification
Solution:
yes I checked with debug never go to my endponit, however I do not need this because I will use directly to my service cointainer instead of endpoint
Jump to solution
16 Replies
Anik
Anik2mo ago
provide code
AgonK
AgonK2mo ago
I excepted to do something like this Action::make('generate_invoices') ->label(('filament.generate_monthly_invoice')) ->icon('heroicon-o-document-duplicate') ->tooltip(('filament.generate_monthly_invoice')) ->action(function (){ $response = route('generate-monthly-invoices', ['title'=>'Auto generate']); }), or ->action(function (){ $response = Http::get(route('generate-monthly-invoices', ['title'=>'Auto generate'])); }), but nothing works @Anik
Anik
Anik2mo ago
are you using it inside forms?
AgonK
AgonK2mo ago
no, only button inside my resource I don't need any form, I will only generate in my API route and send response to this action only for generating notification @Anik
Anik
Anik2mo ago
try
action($this->anyThing())

public function anything() {
// logic here
}
action($this->anyThing())

public function anything() {
// logic here
}
Dennis Koch
Dennis Koch2mo ago
but nothing works
You need to explain "nothing works" a bit more
AgonK
AgonK2mo ago
yes Dennis, nothing work. I don't have any response only click the button and nothing happend there is no error
Dennis Koch
Dennis Koch2mo ago
What are you doing with the "response" after receiving it?
AgonK
AgonK2mo ago
I want to use to send notification, but the response is only route as a string generate-monthly-invoices/title=Auto generate I excpect the response to by my api response
Dennis Koch
Dennis Koch2mo ago
For the first example you only generate a route. But it should for the second example
AgonK
AgonK2mo ago
okay but how its the right way to use my existing API using actions
Dennis Koch
Dennis Koch2mo ago
What's the issue with the second solution? Not sure why you'd do HTTP calls inside your own application instead of calling the code directly, but it should work
AgonK
AgonK2mo ago
yes you are right, I also call service function instead API route The error of second solution is cURL error 28: Operation timed out after 30005 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://127.0.0.1:8000/api/invoices/monthly?title=AutoGenerate
Dennis Koch
Dennis Koch2mo ago
The error is pretty clear isn’t it? Your request takes longer than 30 seconds and is timed out by the client.
Solution
AgonK
AgonK2mo ago
yes I checked with debug never go to my endponit, however I do not need this because I will use directly to my service cointainer instead of endpoint
AgonK
AgonK2mo ago
thank you for you help and remind me xD