LaravelPackages.net
Acme Inc.
Toggle sidebar
performing/laravel-view-helpers

This is my package laravel-view-helpers

425
4
0.4.7
About performing/laravel-view-helpers

performing/laravel-view-helpers is a Laravel package for this is my package laravel-view-helpers. It currently has 4 GitHub stars and 425 downloads on Packagist (latest version 0.4.7). Install it with composer require performing/laravel-view-helpers. Discover more Laravel packages by performing or browse all Laravel packages to compare alternatives.

Last updated

Laravel View Helpers for InertiaJS

This package offers some helpers to build common data strucuture and logic in the context of CRUD applications.

Installation

You can install the package via composer:

composer require performing/laravel-view-helpers

You can publish the config file with:

php artisan vendor:publish --tag="laravel-view-helpers-config"

This is the contents of the published config file:

return [
    'table' => [
        'use_filters' => true,

        'default_filters' => [
            Filter::make('Search')
                ->type('text')
                ->on(function ($query, $value) {
                    return $query->search($value);
                })
        ],

        'default_query' => [
            'per_page' => 15,
        ]
    ]
];

Usage

It's basically headless so it gives you just the data in the right format to build simple tables and forms. You will need to build all the query and filter logic.

Instead of using Inertia::render to return the components data we use Performing\View\Page::class.

class PostController
{
    public function index(Request $request)
    {
        return Page::make('Posts')
            ->table(fn (Table $table) => $table
                ->rows(
                    Post::query()->latest(),
                    PostResource::class
                )
                ->columns([
                    Column::make('ID')->sortable(),
                    Column::make('Title', 'title')->sortable(),
                    Column::make('Azioni')->component(ColumnType::Actions)->sortable(),
                ])
            )->form([
                Input::make('Text'),
                Input::make('Password')->type('password'),
                Input::make('Dropdown')->type('select')->options([ 1 => 'one', 2 => 'two']),
                Input::make('Message')->type('textarea'),
            ])
            ->render('Posts/Index');
    }
}

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments