May Sale! All accounts are 40% off this week.

Devio's avatar
Level 2

remove "api" prefix from api routes laravel 11

My app is an API that doesn't use the web middleware group and doesn't have web routes. How can I customize such that the api routes don't have the "api" prefix.

in bootstrap/app

->withRouting(
        web: __DIR__ . '/../routes/web.php',
        api: __DIR__ . '/../routes/api.php',
        commands: __DIR__ . '/../routes/console.php',
        health: '/up',
    )
0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

withRouting takes an apiPrefix argument, so

  ->withRouting(
    web: __DIR__ . '/../routes/web.php',
    api: __DIR__ . '/../routes/api.php',
    apiPrefix: '',  
    commands: __DIR__ . '/../routes/console.php',
    health: '/up',
)
3 likes

Please or to participate in this conversation.