I'm using Laravel 10 and have created an API using Laravel Sanctum. I want this local API to display a view in my controller. The API functions correctly when tested with Postman, but when it's called in my controller, the page fails to load and eventually times out. I have already set my memory limit in php.ini to 512M, and I'm using PHP 8.1.27. Do you know how I can call the API locally with Sanctum?
module/api/routes/api.php
Route::group(['middleware' => ['auth:sanctum', 'api']], function () {
Route::get('sample', [ApiController::class, 'sample']);
});
Controller
$response = Illuminate\Support\Facades\Http::withHeaders([
"Accept"=> "application/json",
"Authorization" => "Bearer " . env('SANCTUM_AUTH')
])
->get(route('sample').'/', ['type' => '2']);
dd($response);
Error
cURL error 28: Operation timed out after 30006 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://127.0.0.1:8000/sample/?type=2