Share a prop with every Inertia page

HandleInertiaRequests::share() runs for every Inertia response. Keep the query cheap and leave secrets out.

For your AI agent

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

Read https://laravel-vuejs.space/inertia-shared-props-vue.md
HandleInertiaRequests::share() runs for every Inertia response. Keep the query cheap and leave secrets out.
Do not share $request->user() a second time under another key.
Do not share an API token.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Inertia shared data Vue” put a post query in share() and then every page loads it, including the login screen. The setup guide already shares auth.user. Add one more value only when every page needs it.

TL;DR

  • HandleInertiaRequests::share() runs for every Inertia response.
  • Keep the query cheap and leave secrets out.
  • Do not share $request->user() a second time under another key.
  • Do not share an API token.

Who it's for: Laravel + Vue developers on Inertia

Applies to: Laravel 13 · Inertia 3 · Vue 3

The fix#

php
public function share(Request $request): array
{
    return [
        ...parent::share($request),
        'appName' => config('app.name'),
    ];
}

Read it from the page object:

vue
<script setup lang="ts">
import { usePage } from "@inertiajs/vue3";

const page = usePage();
</script>

<template>
  <p>{{ page.props.appName }}</p>
</template>

A list of posts belongs on the controller that renders the list, not here. A shared closure should be lazy when the work is heavy, so a response that does not read the prop does not run it.

What to avoid#

Gotcha

Do not share $request->user() a second time under another key. The kit already did it. Do not share an API token. Shared props are in the HTML of every visit.

FAQ#

How do I share a prop with every Inertia page?

HandleInertiaRequests::share() runs for every Inertia response. Keep the query cheap and leave secrets out.

What goes wrong with Inertia shared data Vue?

Many developers put a post query in share() and then every page loads it, including the login screen. Do not share $request->user() a second time under another key.

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.