我创建了一个新的laravel项目,并添加了带有方法的简单控制器。
然后在我的api.php文件中。我添加了这一行来调用控制器。
Route::get("test", "ApiTestController@test");
我的问题是,当我从邮递员那里调用此api时,我得到“找不到对象!”错误。
我在邮递员中的网址是这样的:
http://localhost/my-project/api/test
我的htaccess文件:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
我必须对配置进行任何更改吗?
答案 0 :(得分:2)
您在URL中缺少公开。检查此URL,您将获得API数据。
http://localhost/my-project/public/api/test
如果您想从网址中删除公开内容。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
现在,您应该可以不用“ /public/index.php/”部分访问该网站。
带有服务器文件。
server.php
重命名为index.php
.htaccess
文件从/public
目录复制到您的Laravel根文件夹。