Laravel Packages

Kinetic: A view-composer package for Inertia.js

Published
Kinetic: A view-composer package for Inertia.js image

Kinetic adds view-composer-like features to the Inertia.js Laravel adapter. Like Laravel view composers, Kinetic can bind data each time a component is rendered from a single location.

Within a service provider, you can call the composer() method to define Inertia composers:

// In a service provider
public function boot()
{
// Class-based composer..
Inertia::composer('User/Profile', UserComposer::class);
}
 
// Composer class
class UserComposer
{
public function compose(ResponseFactory $inertia)
{
$inertia->with('list', [
'foo' => 'bar',
'baz' => 'buzz'
]);
}
}

The composer() method supports closure-based composers as well:

Inertia::composer('User/Profile', function (ResponseFactory $inertia) {
$inertia->with([
'post' => [
'subject' => 'Hello World!',
'description' => 'This is a description.'
]
]);
});

With composers defined in a service provider, your props will include the composing data when you call render():

// Includes bound data from `Inertia::composer('User/Profile')`
Inertia::render('User/Profile');

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

tinkerwell logo
Tinkerwell

Enjoy coding and debugging in an editor designed for fast feedback and quick iterations. It's like a shell for your application – but with multi-line editing, code completion, and more.

Visit Tinkerwell

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article