Skip to main content

Creating Responses

Creating an Inertia response is simple. To get started, invoke inertia::render()inertia.Render()Inertia::render() within your controller or route handler, providing both the name of the JavaScript page component that you wish to render, as well as any properties (data) for the page. In the example below, we will pass a single property (event) which contains four attributes (id, title, start_date and description) to the Event/Show page component.
To ensure that pages load quickly, only return the minimum data required for the page.
Be aware that all data returned from your controllers or handlers will be visible client-side, so be sure to omit sensitive information.

Properties

To pass data from the server to your page components, you can use properties. You can pass various types of values as props, including primitive types, collections, objects, and framework-specific types that are automatically resolved:
Integers outside JavaScript’s safe range lose precision in the browser. You may preserve them as native BigInt values using big integer support.

ProvidesInertiaProperty Interface

In Laravel PHP, when passing props to your components, you may want to create custom classes that can transform themselves into the appropriate data format. While Laravel’s Arrayable interface simply converts objects to arrays, Inertia offers the more powerful ProvidesInertiaProperty interface for context-aware transformations. This interface requires a toInertiaProperty method that receives a PropertyContext object containing the property key ($context->key), all props for the page ($context->props), and the request instance ($context->request).
Once defined, you can use this class directly as a prop value.
The PropertyContext gives you access to the property key, which enables powerful patterns like merging with shared data.

ProvidesInertiaProperties Interface

Root Template Data

There are situations where you may want to access your prop data in your application’s root template. For example, you may want to add a meta description tag, Twitter card meta tags, or Facebook Open Graph meta tags. You can access this data via the page variable in MiniJinja.Props field on inertia.Root in your Go HTML template$page variable in Blade.
Sometimes you may even want to provide data to the root template that will not be sent to your JavaScript page component. This can be accomplished by invoking with_view_datainertia.ViewDatawithViewData.
After invoking with_view_datainertia.ViewDatawithViewData, you can access the defined data as you would typically access a template variablefrom .Data in your root templateas you would typically access a template variable.

Maximum Response Size

To enable client-side history navigation, all Inertia server responses are stored in the browser’s history state. However, keep in mind that some browsers impose a size limit on how much data can be saved within the history state. For example, Firefox has a size limit of 16 MiB and throws a NS_ERROR_ILLEGAL_VALUE error if you exceed this limit. Typically, this is much more data than you’ll ever practically need when building applications.