Skip to main content
Some data rarely changes, is expensive to compute, or is simply large. Rather than including this data in every response, you may use once props. These props are remembered by the client and reused on subsequent pages that include the same prop. This makes them ideal for shared data.

Creating Once Props

To create a once prop, use the Inertia::once() method when returning your response. This method receives a callback that returns the prop data.
return Inertia::render('Billing', [
    'plans' => Inertia::once(fn () => Plan::all()),
]);
After the client has received this prop, subsequent requests will skip resolving the callback and exclude the prop from the response. The client only remembers once props while navigating between pages that include them. Navigating to a page without the once prop will forget the remembered value, and it will be resolved again on the next page that has it. In practice, this is rarely an issue since once props are typically used as shared data or within a specific section of your application.

Forcing a Refresh

You may force a once prop to be refreshed using the fresh() method.
return Inertia::render('Billing', [
    'plans' => Inertia::once(fn () => Plan::all())->fresh(),
]);
This method also accepts a boolean, allowing you to conditionally refresh the prop.
return Inertia::render('Billing', [
    'plans' => Inertia::once(fn () => Plan::all())->fresh($condition),
]);

Refreshing from the Client

You may refresh a once prop from the client-side using a partial reload. The server will always resolve a once prop when explicitly requested.
import { router } from '@inertiajs/vue3'

router.reload({ only: ['plans'] })

Expiration

You may set an expiration time using the until() method. This method accepts a DateTimeInterface, DateInterval, or an integer (seconds). The prop will be refreshed on a subsequent visit after the expiration time has passed.
return Inertia::render('Dashboard', [
    'rates' => Inertia::once(fn () => ExchangeRate::all())->until(now()->addDay()),
]);

Custom Keys

You may assign a custom key to the prop using the as() method. This is useful when you want to share data across multiple pages while using different prop names.
// Team member list...
return Inertia::render('Team/Index', [
    'memberRoles' => Inertia::once(fn () => Role::all())->as('roles'),
]);

// Invite form...
return Inertia::render('Team/Invite', [
    'availableRoles' => Inertia::once(fn () => Role::all())->as('roles'),
]);
Both pages share the same underlying data because they use the same custom key, so the prop is only resolved for whichever page you visit first.

Sharing Once Props

You may share once props globally using the Inertia::share() method.
Inertia::share('countries', Inertia::once(fn () => Country::all()));
Or, for convenience, you may use the shareOnce() method.
Inertia::shareOnce('countries', fn () => Country::all());
You may also chain as(), fresh(), and until() onto the shareOnce method.
Inertia::shareOnce('countries', fn () => Country::all())->until(now()->addDay());
Additionally, you may define a dedicated shareOnce() method in your middleware. The middleware will evaluate both share() and shareOnce(), merging the results.
class HandleInertiaRequests extends Middleware
{
    public function shareOnce(Request $request): array
    {
        return array_merge(parent::shareOnce($request), [
            'countries' => fn () => Country::all(),
        ]);
    }
}

Prefetching

Once props are compatible with prefetching. The client automatically includes any remembered once props in prefetched responses, so navigating to a prefetched page will already have the once props available. Prefetched pages containing an expired once prop will be invalidated from the cache.

Combining with Other Prop Types

The once() modifier may be chained onto deferred, merge, and optional props.
return Inertia::render('Dashboard', [
    'permissions' => Inertia::defer(fn () => Permission::all())->once(),
    'activity' => Inertia::merge(fn () => $user->recentActivity())->once(),
    'categories' => Inertia::optional(fn () => Category::all())->once(),
]);