How to call to an API from my laravel Controller.
My laravel is running on 127:0.0.1:8000. My api’s are also running at this port
now i want to call to this api
Route::get('/task/{task_id}', [TaskDetailsController::class, 'index']);
from my web controller
this is the function where I wrote to call that API
public function index($task, $token)
{
$tokens = Token::where('token', $token)->first();
$tasks = Task::find($task);
$apiUrl = url('/api/task/'.$task);
if ($tokens && $tasks){
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . $token,
])->get(''.$apiUrl);
if ($response->successful()) {
dd($response->json());
} else {
dd("failed");
}
}
else{
dd("baal");
}
}
but I am facing this error
cURL error 28: Operation timed out after 30002 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://localhost:8000/api/task/11
I have tried to write raw php code and use guzzle http package
but didn’t get the fix.