A package that adds view-composer like feature to Inertia.js Laravel adapter

Last update: Jun 19, 2022

Kinetic

A package that adds view-composer like feature to Inertia.js Laravel adapter.

Use to be able to share props based on the Inertia component name.

CircleCI

Installation

$ composer require ambengers/kinetic

Usage

This should be very intuitive if you are already familiar on how view composers work in Laravel.

You can use Inertia::composer() in any service provider to register composers for specific components. The first argument accepts either a string or an array of Inertia components, and the second argument accepts either class string or a closure.

use Inertia;
use Inertia\ResponseFactory;
use App\Composers\UserComposer;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        // Class-based composer..
        Inertia::composer('User/Profile', UserComposer::class);

        // Closure-based composer..
        Inertia::composer('User/Profile', function (ResponseFactory $inertia) {
            //
        });
    }
}

Class-based composers

You can generate your composer class using this command:

$ php artisan kinetic:composer UserComposer

Then you can call the $inertia->with() method within the compose method to set the composed props, like so:

class UserComposer
{
    public function compose(ResponseFactory $inertia)
    {
        $inertia->with('list',  ['foo' => 'bar', 'baz' => 'buzz']);
    }
}

Closure-based composers

If you opt for a closure-based composer, your closure must accept an instance of Inertia\ResponseFactory class as the first argument. Then you can call the with() method from the factory class to set the composed props like so:

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

Multiple composers

You can also set multiple composers to components using array, like so:

Inertia::composer(['User/Profile', 'User/Index'], [
    UserComposer::class,
    function (ResponseFactory $inertia) {
        $inertia->with(...);
    }
]);

The array will be automatically merged with any existing composers for the components.

When you call the Inertia::render('User/Profile') the props should now include the composed data.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

License

Please see the license file for more information.

GitHub

https://github.com/ambengers/kinetic
You might also like...

Laravel Real-time chat app demo with React, Laravel Echo, Breeze, Socket.io, Redis, Inertia.js, TailwindCSS stack.

Laravel Real-time Chat App You can build yours from scratch with the following Medium article https://medium.com/@sinan.bekar/build-a-real-time-chat-a

May 24, 2022

Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.

Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.

Laravel Befriended Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked

Jun 30, 2022

A package that helps to group methods that mostly use for the view presentation purpose.

A package that helps to group methods that mostly use for the view presentation purpose form models to a dedicated presenter class.

Apr 26, 2022

Inertia.js Events for Laravel Dusk

Inertia.js Events for Laravel Dusk Requirements PHP 7.4+ Vue Laravel 8.0 and higher Support We proudly support the community by developing Laravel pac

May 27, 2022

Simple SSR Head for Inertia.js Laravel

Inertia.js Laravel SSR Head Simple SSR Head for Inertia Laravel, solve the social media metadata display of small Inertia.js x Laravel site. NOT a ful

Jun 19, 2022

Pronto Fuel is a heavilly opnionated starter kit for Laravel and Inertia.js powered by Vite

Pronto Fuel Pronto Fuel is a heavilly opnionated starter kit for Laravel and Inertia.js powered by Vite. It ships with autoimporting features and leve

Jun 19, 2022

Tool to convert from composer.yml to composer.json.

composer-yaml This project allows you to convert a composer.yml file into composer.json format. It will use those exact filenames of your current work

Nov 19, 2021

A Laravel package that adds a simple image functionality to any Laravel model

A Laravel package that adds a simple image functionality to any Laravel model

Laraimage A Laravel package that adds a simple image functionality to any Laravel model Introduction Laraimage served four use cases when using images

Feb 3, 2022

This package adds syntax definitions for the Laravel Blade engine.

This package adds syntax definitions for the Laravel Blade engine.

Laravel Blade Highlighter This package adds syntax definitions for the Laravel Blade engine. Works with various Sublime Text version, for older/specif

May 16, 2022
Related tags
Laravel Composable View Composers Package - Compose View Composers from Component Composers
Laravel Composable View Composers Package - Compose View Composers from Component Composers

Laravel Virtuoso Laravel Composable View Composers Package Increase flexibility and reduce code duplication by easily composing complex View Composers

Dec 29, 2021
Aliyun oss filesystem storage adapter for laravel 5. You can use Aliyun OSS just like laravel Storage as usual

Aliyun oss filesystem storage adapter for laravel 5. You can use Aliyun OSS just like laravel Storage as usual

Jun 13, 2022
Stash view is a composer package for Laravel which caches views using Russian Doll Caching methodology.
Stash view is a composer package for Laravel which caches views using Russian Doll Caching methodology.

Stash View Stash view is a composer package for Laravel which caches views using Russian Doll Caching methodology. What is Russian Doll Caching ? It i

Dec 31, 2021
Composer package which adds support for HTML5 elements using Laravels Form interface (e.g. Form::date())

Laravel HTML 5 Inputs Composer package which adds support for HTML5 elements by extending Laravel's Form interface (e.g. Form::date()) Adds support fo

Oct 13, 2020
Jetstrap is a lightweight laravel 8 package that focuses on the VIEW side of Jetstream / Breeze package installed in your Laravel application

A Laravel 8 package to easily switch TailwindCSS resources generated by Laravel Jetstream and Breeze to Bootstrap 4.

Jun 28, 2022
⚡ Laravel Charts — Build charts using laravel. The laravel adapter for Chartisan.
⚡ Laravel Charts — Build charts using laravel. The laravel adapter for Chartisan.

What is laravel charts? Charts is a Laravel library used to create Charts using Chartisan. Chartisan does already have a PHP adapter. However, this li

Jul 1, 2022
this package can help you to test race condition in Laravel Feature Test
this package can help you to test race condition in Laravel Feature Test

Laravel Async Testing this package can help you to test race condition in Laravel Feature Test Requirements Laravel versions 5.7, 6.x, 7.x and 8.x PHP

Apr 29, 2022
An opinionated feature flags package for Laravel

This package provides an opinionated API for implementing feature flags in your Laravel applications. It supports application-wide features as well as model specific feature flags.

Jun 12, 2022
27Laracurl Laravel wrapper package for PHP cURL class that provides OOP interface to cURL. [10/27/2015] View Details

Laracurl Laravel cURL Wrapper for Andreas Lutro's OOP cURL Class Installation To install the package, simply add the following to your Laravel install

Sep 9, 2018
This package provides a Logs page that allows you to view your Laravel log files in a simple UI
This package provides a Logs page that allows you to view your Laravel log files in a simple UI

A simplistics log viewer for your Filament apps. This package provides a Logs page that allows you to view your Laravel log files in a simple UI. Inst

May 19, 2022