Php Laravel api调用失败
所以我在larachat上问了这个问题,然后在google上搜索。我知道以前也有人问过类似的问题,但没有一个对我有用 我试图加载Php Laravel api调用失败,php,laravel,api,vue.js,laravel-5.6,Php,Laravel,Api,Vue.js,Laravel 5.6,所以我在larachat上问了这个问题,然后在google上搜索。我知道以前也有人问过类似的问题,但没有一个对我有用 我试图加载post的注释,但请求甚至没有到达api.php以下是我的请求: axios.get(`/api/posts/${this.post.id}/comments`) 在api.php中,我有以下内容: Route::get('/posts/{id}/comments', function(){ return "got here"; }); 但是我得到了错误:
post
的注释,但请求甚至没有到达api.php
以下是我的请求:
axios.get(`/api/posts/${this.post.id}/comments`)
在api.php中,我有以下内容:
Route::get('/posts/{id}/comments', function(){
return "got here";
});
但是我得到了错误:gethttp://localhost/api/posts/2/comments 404(未找到)
即使我手动尝试使用:http://localhost/api/posts/2/comments
我仍然收到请求的URL/api/posts/2/注释在此服务器上找不到。
我不知道我是否可以通过这种方式访问它,但我已经尝试过了
我运行phpartisan route:list
,在列表中得到如下结果:
GET | HEAD | api/posts/{id}/comments | | | Closure | api |
如果您在localhost中运行应用程序,那么您的url必须是
具有包含的基本url。然后您可以通过添加基本url来调用url您确定
http://localhost/
是您的laravel应用程序的托管地吗?当您访问http://localhost/
?首先尝试在.env文件中正确设置应用程序URL。@JacobGoh不,它在词典中/public
@AbidRaza我的hompage URL是http://localhost/lexicon/public/home
那么我应该将APP\u URL
设置为:APP\u URL=http://localhost/lexicon
而不是:应用程序URL=http://localhost
只是想知道您是否确定它在端口80上为您的站点提供服务?您使用的是php artisan-serve
?在JQuery中,很容易给出像var-url='{{route(“url”)}}这样的链接代码>你能告诉我如何给url,这样它也能在实际的服务器上工作吗?在实际的服务器上,你将把域指向扩展公共文件夹。在实际服务器中,您不必担心。因为域将指向公用文件夹。然后这个/api/posts/${this.post.id}/comments将按原样工作。在本地,只需使用PHP artisan serve运行应用程序,使应用程序在单独的端口中运行,这样您就不必更改代码。您是说,我没有机会使用wamp访问该url?因为当我手动尝试的时候。该链接的工作方式为http://localhost/lexicon/public/api/posts/2/comments