Skip to main content
zerotal

Documentation


Documentation / @zerotal/inertia / share

Function: share()

Call Signature

share(key, value): void

Defined in: inertia/src/share.ts:42

Register shared prop(s) that Zerotal includes on every Inertia page, so page components can read them without each controller passing them explicitly.

Parameters

key

string

The shared prop name (single-key overload) — or, in the object overload, the map of names to values.

value

unknown

The value for key (single-key overload only); a plain value, a per-request factory, or a prop wrapper.

Returns

void

Remarks

Call once at boot (typically in a service provider) — a later share() of the same key overwrites the previous value. Values may be plain data, a factory function (re-evaluated lazily per request, e.g. to read the current user), or a prop wrapper. The built-in shared keys (auth, flash, errors, old) are always present in addition to whatever you register here; see sharedProps.

Two call styles: a single key/value pair, or an object of many at once.

Example

// In a service provider's boot() — available on every page (auth/flash/errors/old
// are already built in; register your own extras here).
Inertia.share({
  appName: 'Acme',
  permissions: () => Auth.user()?.permissions ?? [],  // factory re-runs each request
});

// Or a single key:
Inertia.share('year', () => new Date().getFullYear());

Call Signature

share(values): void

Defined in: inertia/src/share.ts:43

Register shared prop(s) that Zerotal includes on every Inertia page, so page components can read them without each controller passing them explicitly.

Parameters

values

Record<string, unknown>

Returns

void

Remarks

Call once at boot (typically in a service provider) — a later share() of the same key overwrites the previous value. Values may be plain data, a factory function (re-evaluated lazily per request, e.g. to read the current user), or a prop wrapper. The built-in shared keys (auth, flash, errors, old) are always present in addition to whatever you register here; see sharedProps.

Two call styles: a single key/value pair, or an object of many at once.

Example

// In a service provider's boot() — available on every page (auth/flash/errors/old
// are already built in; register your own extras here).
Inertia.share({
  appName: 'Acme',
  permissions: () => Auth.user()?.permissions ?? [],  // factory re-runs each request
});

// Or a single key:
Inertia.share('year', () => new Date().getFullYear());