Prefix a Laravel API with v1

routes/api.php is already under /api. Add v1 inside the file and keep Inertia pages out of it.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/laravel-api-v1-prefix-vue.md
routes/api.php is already under /api. Add v1 inside the file and keep Inertia pages out of it.
Do not point an Inertia Link at /api/v1/posts from a page.
Do not duplicate the whole web CRUD under v1 when Inertia already renders those pages.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Laravel API versioning Vue” mount Inertia on /api/v1 or prefix the file twice and call /api/api/v1. bootstrap/app.php already gives routes/api.php the api prefix and the api middleware group. Add only the version:

TL;DR

  • routes/api.php is already under /api.
  • Add v1 inside the file and keep Inertia pages out of it.
  • Do not point an Inertia Link at /api/v1/posts from a page.
  • Do not duplicate the whole web CRUD under v1 when Inertia already renders those pages.

Who it's for: Laravel + Vue developers

Applies to: Laravel 13 · Vue 3 · Sanctum

The fix#

php
Route::prefix('v1')->middleware('auth:sanctum')->group(function () {
    Route::get('/posts', [Api\PostController::class, 'index']);
});

The URL is /api/v1/posts. It returns JSON. The Vue starter kit does not navigate there. A separate SPA, the one in the SPA guide, is the client that calls it. Cookie auth for that SPA is the Sanctum guide. A token is a different client.

What to avoid#

Gotcha

Do not point an Inertia Link at /api/v1/posts from a page. Link expects an Inertia response. A JSON body mounts as a broken visit. Do not duplicate the whole web CRUD under v1 when Inertia already renders those pages.

FAQ#

How do I prefix a Laravel API with v1?

routes/api.php is already under /api. Add v1 inside the file and keep Inertia pages out of it.

What goes wrong with Laravel API versioning Vue?

Many developers mount Inertia on /api/v1 or prefix the file twice and call /api/api/v1. Do not point an Inertia Link at /api/v1/posts from a page.

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.