【发布时间】:2023-03-31 22:10:01
【问题描述】:
所以我在 larachat 中问了这个问题并在 google 中搜索。我知道以前有人问过类似的问题,但没有一个对我有用。
我正在尝试加载 post 的评论,但请求甚至没有到达 api.php 这是我所做的请求:
axios.get(`/api/posts/${this.post.id}/comments`)
比我在 api.php 里面有这个:
Route::get('/posts/{id}/comments', function(){
return "got here";
});
但我得到了错误:GET http://localhost/api/posts/2/comments 404 (Not Found)
即使我手动尝试使用以下方式访问 api:http://localhost/api/posts/2/comments
我仍然收到 The requested URL /api/posts/2/comments was not found on this server.
我不知道我是否可以通过这种方式访问它,但我试过了。
我运行 php artisan route:list 并在列表中得到它,如下所示:
GET|HEAD | api/posts/{id}/comments | | Closure | api |
【问题讨论】:
-
你确定
http://localhost/是你的 laravel 应用托管的地方吗?当您访问http://localhost/时,您看到了什么? -
先尝试在.env文件中正确设置APP_URL。
-
@JacobGoh 不,它在
lexicon和/public内 -
@AbidRaza 我的主页网址是
http://localhost/lexicon/public/home所以我应该将APP_URL设置为:APP_URL=http://localhost/lexicon而不是:APP_URL=http://localhost -
只是想知道您是否确定它在端口 80 上为您的站点提供服务?你在使用
php artisan serve吗?
标签: php laravel api vue.js laravel-5.6