Search code examples
phplaravel

laravel api route not found but exists in route list


I'm trying to add a patch route to routes/api.php but I get "route not found" even after trying route:cache. it's registered in route:list and other routes in that scope are working.

this is my code:

<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::group([
    'prefix' => 'v1',
    'namespace' => 'App\Http\Controllers\Api\V1',
], function() {

    Route::group([
        'prefix' => '/users',
    ], function() {
        Route::get('/{user}', 'UsersController@show');
        Route::patch('/{user}/updateStatus', 'UsersController@updateStatus');
    });

});

and this is my code in controller action:


<?php

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\User;

class UserController extends Controller {
    public function updateStatus(Request $request, User $user) {
         # my logic
    }
}

the route is registered as /api/v1/users/{user}/updateStatus but I get 404.

by the way, I'm using laravel 8 and php 7.3


Solution

  • I think web server will automatically change url to lowercase so you must use lowercase in laravel route,so you must change "updateStatus" to "updatestatus" or "update-status"