首页 > 解决方案 > Laravel API:上传后出现 NotFoundHttpException

问题描述

我最终确定了基于 Laravel 的 REST API。将 API 上传到共享虚拟主机后,我每次都会从 RouteCollection 收到 NotFoundHttpException 错误。

公用文件夹正在工作并显示正常。但是,当我尝试将 API 与邮递员一起使用时,我会收到以下错误:

{
"message": "",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
"file": "/var/www/vhosts/cloud1.openhandwerk.de/httpdocs/API_oH/Connector/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",
"line": 179,
"trace": [

现在,当我通过浏览器访问该页面时,我只会收到 404 错误。

我的 api.php 文件

<?php

use Illuminate\Http\Request;

Route::prefix("v1")->group(function() {
  Route::post('login', 'Api\v1\UserController@login');
  Route::post('register', 'Api\v1\UserController@register');

  Route::group(['middleware' => 'auth:api'], function(){
    // Customers
    Route::get("customers", 'Api\v1\CustomerController@index');
    // Route::get("customer/{id}", "API/v1/CustomerController@show");
    // Route::post("customer", "API/v1/CustomerController@store");
    // Route::put("customers", "API/v1/CustomerController@store");
    // Route::delete("customers", "API/v1/CustomerController@destroy");
  });
});

标签: phplaravelapiroutes

解决方案


我认为您缺少前缀api。请使用route:list命令列出所有带有路径的路由。

php artisan route:list

推荐阅读