[英]Laravel: resource was not found on this server
I am developing a Laravel 7 website for web and API.我正在为 web 和 API 开发一个 Laravel 7 网站。 I have completed the API and I can call all routes there but I have got an error when trying to access a route on the web.php
我已经完成了 API 并且可以调用那里的所有路由,但是在尝试访问 web.php 上的路由时出现错误
Route::get("/products", 'web\ProductController@index')->name("products.all");
the error says错误说
The requested resource /products was not found on this server.
在此服务器上找不到请求的资源 /products。
I have run route:list command and the route is listed there.this is what it prints我已经运行了 route:list 命令,并且路线列在那里。这就是它打印的内容
[{"domain":null,"method":"GET|HEAD","uri":"\/","name":null,"action":"Closure","middleware":"web"},{"domain":null,"method":"GET|HEAD","uri":"api\/documentation","name":"l5-swagger.api","action":"L5Swagger\\Http\\Controllers\\SwaggerController@api","middleware":""},{"domain":null,"method":"GET|HEAD","uri":"api\/oauth2-callback","name":"l5-swagger.oauth2_callback","action":"L5Swagger\\Http\\Controllers\\SwaggerController@oauth2Callback","middleware":""},{"domain":null,"method":"GET|HEAD","uri":"docs\/asset\/{asset}","name":"l5-swagger.asset","action":"L5Swagger\\Http\\Controllers\\SwaggerAssetController@index","middleware":""},{"domain":null,"method":"GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS","uri":"docs\/{jsonFile?}","name":"l5-swagger.docs","action":"L5Swagger\\Http\\Controllers\\SwaggerController@docs","middleware":""},{"domain":null,"method":"GET|HEAD","uri":"products","name":"products.all","action":"App\\Http\\Controllers\\web\\ProductController@index","middleware":"web"}]
and the controller和 controller
class ProductController extends Controller
{
public function index()
{
return 1;
}
}
How can I fix it?我该如何解决?
use this Route::namespace('web')->group(function () {
Route::get("/products", 'ProductController@index')->name("products.all");
});
and use php artisan key:generate并使用 php 工匠密钥:生成
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.