php - laravel MethodNotAllowedHttpException 不被支持
问题描述
当我运行 php artisan route:list 我可以找到路线
GET|HEAD | accounting/sales
但是每当我使用邮递员发送请求时,我都会收到同样的错误
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: The GET method is not supported for this route. Supported methods: POST. in file C:\xampp\htdocs\projects\controller\controllerapi\vendor\laravel\framework\src\Illuminate\Routing\AbstractRouteCollection.php on line 117
当我尝试将请求类型更改为 POST 时,我得到了同样的错误,但告诉我它只支持这样的获取:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: The POST method is not supported for this route. Supported methods: GET, HEAD. in file C:\xampp\htdocs\projects\controller\controllerapi\vendor\laravel\framework\src\Illuminate\Routing\AbstractRouteCollection.php on line 117
这是我的 api.php
Route::group([
'prefix' => 'auth'
], function () {
Route::post('shortlink', [AuthController::class, 'shortLink']);
});
// --- LICENSE AUTH ---
Route::group([
'middleware' => [LicenseAuth::class]
], function () {
// --- UNAUTHENTICATED ---
Route::group([
'prefix' => 'auth'
], function () {
Route::post('login', [AuthController::class, 'login'])->name('login');;
});
Route::group([
'prefix' => 'accounting'
], function (){
Route::get('sales', [salesPerDay::class, 'getItems']);
});
});
});
这是我的课
<?php
class salesPerDay extends Controller
{
public function getItems()
{
$items = [];
$stores = Store::get();
$connectB = new ConnectToDatabase();
foreach($stores as $store) {
//CONNECT TO DATABASE
if(!$connectB->connect($store))
continue;
$collection = Item::select("id")->get();
foreach($collection as $item) {
$items[] = $item;
}
}
return response()->json($items);
}
}
解决方案
推荐阅读
- sql - 获取Oracle分层查询中的所有子路径
- javascript - 从反应数组中删除项目(卡)
- functional-testing - 如何在 appbuild 上测试模型级触发器?
- python - 将 Spyder 升级到 4.0.1 时出错:ModuleNotFoundError: No module named 'IPython.core.inputtransformer2'
- android - 如何在 JNI 中编辑 jobjectArray 并将其传递回 Java
- amazon-web-services - 如何使 ip 指向 AWS 上的其他 ip 和端口(来自两个 apache 虚拟主机)
- javascript - 我可以在 JavaScript 中声明变量的地方
- electron - 在 Electron 的“appData”中写入文件。在哪里添加 import { app } from "electron";?
- docusignapi - DocuSign API 方法信封.listStatusChanges 不显示共享给我的用户的信封
- ios - 如何让我的 UIButton 标题有一些填充?