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:Jump to 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
16 Replies
provide code
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
are you using it inside forms?
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
try
but nothing worksYou need to explain "nothing works" a bit more
yes Dennis, nothing work. I don't have any response only click the button and nothing happend
there is no error
What are you doing with the "response" after receiving it?
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 responseFor the first example you only generate a route.
But it should for the second example
okay but how its the right way to use my existing API using actions
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
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
The error is pretty clear isn’t it? Your request takes longer than 30 seconds and is timed out by the client.
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
thank you for you help and remind me xD