This is the documentation for
v3.
You can switch versions in the menu on the left/at the top.
Check your current version with the following command:
composer show spatie/laravel-data
Inertia.js lets you quickly build modern single-page React, Vue, and Svelte apps using classic server-side routing and controllers.
Laravel Data works excellent with Inertia.
You can pass a complete data object to an Inertia response:
return Inertia::render('Song', SongsData::from($song));
##Lazy properties
This package supports lazy properties, which can be manually included or excluded.
Inertia has a similar concept called lazy data evaluation, where some properties wrapped in a closure only get evaluated and included in the response when explicitly asked.
This package can output specific properties as Inertia lazy props as such:
class SongData extends Data
{
public function __construct(
public Lazy|string $title,
public Lazy|string $artist,
) {
}
public static function fromModel(Song $song): self
{
return new self(
Lazy::inertia(fn() => $song->title),
Lazy::inertia(fn() => $song->artist)
);
}
}
Now within your JavaScript code, you can include the properties as such:
Inertia.reload((url, {
only: ['title'],
});