PHP code example of ambengers / kinetic

1. Go to this page and download the library: Download ambengers/kinetic library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ambengers / kinetic example snippets


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) {
            //
        });
    }
}

// Components within User directory will receive data from UserComposer class
Inertia::composer('User/*', UserComposer::class);

// All components will receive data from GlobalComposer class
Inertia::composer('*', GlobalComposer::class);

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

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

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