首页 > 解决方案 > 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);
    }

  
}

标签: phplaravelrestilluminate

解决方案


推荐阅读