• Reading time ~ 1 min
  • 18.06.2022

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.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297