我在Windows上使用xampp在Laravel 5.3上启动了一个新项目,我在未来也设置了cors包(https://github.com/barryvdh/laravel-cors)以在其他域中执行请求。
但是在使用邮递员的localhost上路由不起作用我在/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工匠路线列表:
+--------+----------+------------------------+----------+------------------------------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+------------------------+----------+------------------------------------------------------------------------+--------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | api/hello | | App\Http\Controllers\AppController@hello | api |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | home | | App\Http\Controllers\HomeController@index | web,auth |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web,guest |
| | POST | login | | App\Http\Controllers\Auth\LoginController@login | web,guest |
| | POST | logout | logout | App\Http\Controllers\Auth\LoginController@logout | web |
| | POST | password/email | | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web,guest |
| | GET|HEAD | password/reset | | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest |
| | POST | password/reset | | App\Http\Controllers\Auth\ResetPasswordController@reset | web,guest |
| | GET|HEAD | password/reset/{token} | | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web,guest |
| | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController@showRegistrationForm | web,guest |
| | POST | register | | App\Http\Controllers\Auth\RegisterController@register | web,guest |
答案 0 :(得分:0)
我认为您因错误的网址细分而导致此错误:/ public URL应为:/ public / api / hello
答案 1 :(得分:0)
在网址部分中,移除myproject
部分。