Creating Responses
Creating an Inertia response is simple. To get started, invoke theInertia::render() method within your controller or route, 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.
Be aware that all data returned from the controllers 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, arrays, objects, and several Laravel-specific types that are automatically resolved:toArray() method. Responsable objects like API resources and JSON responses are resolved through their toResponse() method.
ProvidesInertiaProperty Interface
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 PropertyContextobject containing the property key ($context->key), all props for the page ($context->props), and the request instance ($context->request).
PropertyContext gives you access to the property key, which enables powerful patterns like merging with shared data.
ProvidesInertiaProperties Interface
In some situations you may want to group related props together for reusability across different pages. You can accomplish this by implementing the ProvidesInertiaProperties interface.
This interface requires a toInertiaProperties method that returns an array of key-value pairs. The method receives a RenderContext object containing the component name ($context->component) and request instance ($context->request).
render() and with() methods.
Root Template Data
There are situations where you may want to access your prop data in your application’s root Blade 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.
withViewData method.
withViewData method, you can access the defined data as you would typically access a Blade 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 aNS_ERROR_ILLEGAL_VALUE error if you exceed this limit. Typically, this is much more data than you’ll ever practically need when building applications.