php - 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");
});
});
解决方案
我认为您缺少前缀api
。请使用route:list
命令列出所有带有路径的路由。
php artisan route:list
推荐阅读
- mysql - 如何根据 SQL 中的另一列值向表中添加列
- vue.js - 动态路由器链接将 *slash* 更改为 %2F
- python - Python中的while循环和逻辑运算符 - 它是如何工作的?
- elasticsearch - nifi 将文本文件转换为 json
- sql-server - 波斯字符的 NVARCHAR SQL 类型问题
- javascript - Safari 浏览器上的 Light Gallery 插件问题
- node.js - bundle.js 加载速度很慢
- javascript - 如何从 url 获取 Json 然后添加到 html 中的表格?
- jenkins - 詹金斯的建筑在舞台上永远暂停,“没有步骤”
- openstreetmap - 尝试获取地名并将其添加到来自大型 osm 文件的输出 csv 文件