performing / laravel-view-helpers
This is my package laravel-view-helpers
0.4.7
2023-06-06 09:59 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^9.0|^10.0
- inertiajs/inertia-laravel: *
- spatie/laravel-package-tools: ^1.13.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpunit/phpunit: ^9.5
- tightenco/ziggy: ^1.5
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.