laravel - Laravel api路由与邮递员不工作

  显示原文与译文双语对照的内容
89 3

我在 Laravel 上使用xampp启动了一个新项目,并在未来的其他领域中使用了cors包( https://github.com/barryvdh/laravel-cors ) 来请求其他领域的。

但是在使用邮差的主机上,路由不工作我在/routes/api. php上有这个:

Route::get('/hello', 'AppController@hello');

在控制器上:

public function hello()
 {
 return"hello!";
 }

邮递员:

http://localhost/myproject/api/hello

响应"找不到对象错误 404",我尝试使用 http://localhost:80/myproject/api/hello 和相同的响应。

当我将这个 http://localhost/myproject/public/api/hello,我得到响应:" RouteCollection.php 第 161行的NotFoundHttpException:"

我不明白这是 Laravel 5.3 Bug 还是别的什么?这是我的php route列表:

+--------+----------+------------------------+----------+------------------------------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+------------------------+----------+------------------------------------------------------------------------+--------------+
| | GET|HEAD |/| | Closure | web |
| | GET|HEAD | api/hello | | AppHttpControllersAppController@hello | api |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | home | | AppHttpControllersHomeController@index | web,auth |
| | GET|HEAD | login | login | AppHttpControllersAuthLoginController@showLoginForm | web,guest |
| | POST | login | | AppHttpControllersAuthLoginController@login | web,guest |
| | POST | logout | logout | AppHttpControllersAuthLoginController@logout | web |
| | POST | password/email | | AppHttpControllersAuthForgotPasswordController@sendResetLinkEmail | web,guest |
| | GET|HEAD | password/reset | | AppHttpControllersAuthForgotPasswordController@showLinkRequestForm | web,guest |
| | POST | password/reset | | AppHttpControllersAuthResetPasswordController@reset | web,guest |
| | GET|HEAD | password/reset/{token} | | AppHttpControllersAuthResetPasswordController@showResetForm | web,guest |
| | GET|HEAD | register | register | AppHttpControllersAuthRegisterController@showRegistrationForm | web,guest |
| | POST | register | | AppHttpControllersAuthRegisterController@register | web,guest |
时间:原作者:0个回答

147 2

我认为由于缺少网址段,你将收到这里错误:/public 网址应该是:/public/api/hello

原作者:
...