Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AbdulBaari's avatar

GET parameters from API routes not getting detected

I use deployer to deploy my laravel application from a repository. Locally the application functions as intended, however, on the server there is unexpected behavior. I have a simple route in api.php (see below) that returns this error: Too few arguments to function App\Http\Controllers\ApiController::user(), 0 passed and exactly 1 expected.

api.php

Route::get('user/{id}', 'ApiController@user');

ApiController.php

public function user($id)
{
     return response()->json([
         'test' => $id
     ]);
}

php artisan route:list

+--------+----------+---------------------+-----------------------------+-----------------------------------------------------+------------+
| Domain | Method   | URI                 | Name                        | Action                                              | Middleware |
+--------+----------+---------------------+-----------------------------+-----------------------------------------------------+------------+
|        | GET|HEAD | api/api/user/{id}   | generated::vyXpDYUXPJPIHU1b | App\Http\Controllers\ApiController@user             | api        |

(I'm unsure why the URI is prefixed with "api/api/" rather than just "api/", it still renders on /api/user/)

Additionally, routes that return 404 errors locally (i.e. routes that don't exist) return error 500 on the server with the error: No routes found for "/routename/", which makes me wonder if this could mean that there is a problem with routing in general on the server?

Using laravel 7.0.0 and PHP 7.3.17

0 likes
6 replies
shez1983's avatar

check in RouteServiceProvider.. if using api.php route file, laravel already prepends it with api/ so you dont have to in api.php

AbdulBaari's avatar

I'm not prefixing the route with /api as you can see in the route i posted above. Laravel is prefixing it with /api/api for some unknown reason.

MThomas's avatar

@abdulbaari can you still show your RouteServiceProvider? it might be prefixed there for some reason.

AbdulBaari's avatar

Here's my RouteServiceProvider.php

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        //

        parent::boot();
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->mapApiRoutes();

        $this->mapWebRoutes();

        //
    }

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }
}
AbdulBaari's avatar
AbdulBaari
OP
Best Answer
Level 1

I've resolved this issue by transferring my files to a new laravel 7.6 project.

hugoisrr's avatar

This answer might not be related to the original question, but I faced a situation that new API routes were no longer detected. After searching and debugging. I wasn't able to find an answer. I asked a co-worker. The solution was:

php artisan optimize:clear

I hope this could help you in the future.

1 like

Please or to participate in this conversation.