简体   繁体   English

找不到 Laravel API 路由

[英]Laravel API Route Not Found

I'm trying to test an API route, but I always get 404 Not Found .我正在尝试测试 API 路由,但我总是收到404 Not Found

I'm using this command:我正在使用这个命令:

curl http://localhost:8000/api/veip

This is my routes/api.php这是我的routes/api.php

<?php

use Illuminate\Http\Request;

Route::get('/veip', function () {
    return 'Hello World';
});

And this is my php artisan route:list output:这是我的php artisan route:list输出:

+--------+----------+----------+------+---------+------------+
| Domain | Method   | URI      | Name | Action  | Middleware |
+--------+----------+----------+------+---------+------------+
|        | GET|HEAD | /        |      | Closure | web        |
|        | GET|HEAD | api/veip |      | Closure | api        |
+--------+----------+----------+------+---------+------------+

So the route does exists所以路线确实存在

I don't know what's going on here...我不知道这里发生了什么......

运行sudo a2enmod rewrite以启用 .htaccess 文件上的 mod_rewrite,然后sudo service apache2 restart

试试 php artisan route:clear 可能对你有用

check routing middleware https://laravel.com/docs/8.x/routing#route-groups ?检查路由中间件https://laravel.com/docs/8.x/routing#route-groups

Route::middleware('api')->group(function () {

    Route::get('testroute', [TestController::class, 'index']); 
}

URL:网址:

http://127.0.0.1:8000/api/testroute

你需要调用 http://my_localhost_link/ api /someroute。

我之前遇到过同样的问题,结果我只需要运行php artisan optimize并且我的路线就在那里

您需要使用以下命令搜索 Api/routes:php artisan api:routes(工匠命令)而不是 php artisan route:list。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM