我刚刚在本地主机目录中创建了一个新的Laravel项目,并在 api.php 文件中创建了Laravel路由。
Route::post('/home', 'HomeAPI@index');
当我尝试从 Postman 向链接localhost/home
发送发帖请求时,出现以下错误:
Sorry, the page you are looking for could not be found.
1/1 NotFoundHttpException in RouteCollection.php line 161:
那我该如何访问我的 /home
路由?
When trying to access a API route (route mentioned in api.php) from Laravel, just add /api to the link you are trying to access. In this case, your link would be:
localhost/api/home
This should solve your problem.
Everything in api.php
is under /api
so in your case it's localhost/api/home