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

Related tags

Laravel kinetic
Overview

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.

You might also like...
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

This package provides a Filament resource to view all Laravel sent emails.
This package provides a Filament resource to view all Laravel sent emails.

This package provides a Filament resource to view all Laravel outgoing emails. It also provides a Model for the database stored emails. Installation Y

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

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

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.

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

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

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

Simple laravel hook for adding meta tags to head for inertia

laravel seo hook for js frameworks simple hook for adding meta tags to head/head for js frameworks inertia:react,vue, etc... in app/Meta.php put M

Comments
  • Attaching a composer to all components

    Attaching a composer to all components

    Hi, I use your package, it's very nice for work with composers like views but i saw that it is not possible to register composers for all components, such as view composers (The composer method also accepts the * character as a wildcard, allowing you to attach a composer to all views). So I tried to add this feature to your package, I hope it is useful.

    opened by sadegh19b 3
  • Method Inertia\ResponseFactory::composer does not exist.

    Method Inertia\ResponseFactory::composer does not exist.

    After installing the package, I am receiving the following exception.

    Method Inertia\ResponseFactory::composer does not exist.
    

    I registered a composer in the AppServiceProvider boot method.

    public function boot()
    {
        Inertia::composer(Enum::Dashboard, CourseComposer::class);
    }
    

    I am using Laravel version 9.19

    opened by Kreshnik 1
  • Add ability to use wildcards in composer registration

    Add ability to use wildcards in composer registration

    Closes #4

    This PR adds the ability to use wildcards in composer registration that allows you to register one composer across many that match the asterisk pattern.

    Ex:

    // Match any nested component in the "Reports" folder:
    Inertia::composer('Reports/*', ReportComposer::class);
    
    // Match any component:
    Inertia::composer('*', AppComposer::class);
    

    Please let me know if you'd like anything adjusted, thanks for your time! ❤️

    opened by stevebauman 1
  • Wildcard Composers

    Wildcard Composers

    Hi there @ambengers!

    I really like this package (wish it was merged into the core of Inertia).

    It would be super awesome if we could use a wildcard to register composers for components in a directory.

    For example:

    Inertia::composer('Reports/*', ReportComposer::class);
    

    Is this something you'd consider in a PR?

    opened by stevebauman 0
Releases(1.8)
Owner
Marvin Quezon
Developer.
Marvin Quezon
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

Yitzchok Willroth 68 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

jacob 517 Dec 29, 2022
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

Bhushan Gaikwad 18 Nov 20, 2022
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

Small Dog Studios 11 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.

null 686 Dec 28, 2022
⚡ 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

Erik C. Forés 31 Dec 18, 2022
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

Recca Tsai 61 Nov 5, 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.

Ryan Chandler 157 Nov 24, 2022
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

Renoki Co. 720 Jan 3, 2023
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

zjango 8 Sep 9, 2018