performing/laravel-view-helpers

This is my package laravel-view-helpers

0.4.7 2023-06-06 09:59 UTC

This package is not auto-updated.

Last update: 2024-04-09 14:01:49 UTC


README

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.