Laravel API路线在邮递员中不起作用

Laravel API路线在邮递员中不起作用,laravel,Laravel,我正在尝试为我的应用程序创建API,但API路由不起作用。我在routes/api.php中有一个路由,我还创建了一个名为hotelplex.test的虚拟主机名 app\Providers\RouteServiceProvider.php protected function mapApiRoutes() { Route::domain(env('API_DOMAIN')) ->middleware('api') ->namespace(

我正在尝试为我的应用程序创建API,但API路由不起作用。我在routes/api.php中有一个路由,我还创建了一个名为
hotelplex.test
的虚拟主机名

app\Providers\RouteServiceProvider.php

protected function mapApiRoutes()
{
    Route::domain(env('API_DOMAIN'))
         ->middleware('api')
         ->namespace($this->namespace)
         ->group(base_path('routes/api.php'));
}
Route::get('/guests', function() {

    $guest = [
        "name" => "Harshith"
];
    return $guest;
});

.env

API_DOMAIN = api.hotelplex.test
routes\api.php

protected function mapApiRoutes()
{
    Route::domain(env('API_DOMAIN'))
         ->middleware('api')
         ->namespace($this->namespace)
         ->group(base_path('routes/api.php'));
}
Route::get('/guests', function() {

    $guest = [
        "name" => "Harshith"
];
    return $guest;
});

当我使用邮递员访问
api.hotelplex.dev/guests
时,它会显示下面的响应

Could not get any response
There was an error connecting to http://api.hotelplex.dev/guests.
Why this might have happened:
The server couldn't send a response:
Ensure that the backend is working properly
Self-signed SSL certificates are being blocked:
Fix this by turning off 'SSL certificate verification' in Settings > General
Proxy configured incorrectly
Ensure that proxy is configured correctly in Settings > Proxy
Request timeout:
Change request timeout in Settings > General

您应该在url中插入/api/。 例如
http://api.hotelplex.dev/api/guests

这是laravel中的默认功能,用于将routes/api.php中的所有路由映射为/api/prepend

您可以在
RouteServiceProvider.php
中禁用或更改“api”一词, 通过编辑此函数

protected function mapApiRoutes()
{
    Route::prefix('api')
         ->middleware('api')
         ->namespace($this->namespace)
         ->group(base_path('routes/api.php'));
}
例如:

protected function mapApiRoutes()
{
    Route::prefix('my_custom_prefix')
         ->middleware('api')
         ->namespace($this->namespace)
         ->group(base_path('routes/api.php'));
}

你说你设置了
hotelplex.test
,但你正试图在Postmanyeah中获取
hotelplex.dev
,对不起,但它在
hotelplex.test中不起作用。test
也将上传图片。我刚刚重新上传了
hotelplex.test的响应。现在检查你的url是否正确。