无法使用邮递员软件访问 laravel 5.5 API 路由



我的 api.php路由是

Route::get('/allposts','PostController@index');

控制器功能是和与 Web 一起使用.php路由文件

public function index()
{
$posts= Post::all();
return PostResource::collection($posts);
}

我的资源是 toArray 函数是

public function toArray($request)
{
return parent::toArray($request);
}

使用 GET 的邮递员链接是 "queuetest.com/api/allposts">
"http://queuetest.com/api/allposts" 两者都不起作用 并在邮递员和浏览器中获取结果:抱歉找不到您要查找的页面

当您在索引方法中作为第一行var_dump('test');die();时,您是否得到除Sorry the page you're looking for could not be found消息以外的其他内容。

编辑:尝试删除然后在/allPosts之前/

另一个编辑:检查您的RouteServiceProvider是否将mapApiRoutes前缀设置为'api'

如果您使用的是现成的默认路由配置,如果要在/api命名空间中访问路由,则应将路由放在routes/api.php中。目前,该路线应该可以从 http://queuetest.com/allposts 访问。

可以在AppProvidersRouteServiceProviders.php中配置此行为。如果修改了路由配置,则有许多因素可能导致此行为,如果不看到更多代码,则无法找到问题所在。

最新更新