Over Dose
Over Dose

Reputation: 41

laravel MethodNotAllowedHttpException get not supported

when i run php artisan route:list i can find the route

 GET|HEAD  | accounting/sales  

but whenever i send the request using postman i get the same error

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

and when i try to to change the request type to POST i get the same error but telling me that it only supports the get like this :

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

this is my 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']);

        });
    });
});

and this is my class

<?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);
    }

  
}

Upvotes: 0

Views: 627

Answers (0)

Related Questions