figlabhq / crud-resource-for-backpack
Build CRUD panels using fluent field definitions.
Installs: 1 369
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 4
Forks: 3
Open Issues: 5
Requires
- backpack/crud: ^5.0|^6.0|v6.x-dev
- illuminate/support: ^7|^8|^9|^10
Requires (Dev)
- orchestra/testbench: ~5|~6
- phpunit/phpunit: ~9.0
README
This package allows creating CRUD panels for Backpack for Laravel administration panel using fluent field definitions.
This is heavily inspired by Laravel Nova.
What does it offer?
- Define Resources once, get all configurations ready for CRUD panels 🚀
- Get IDE hints - these are all PHP classes 😉
- Avoid long, nested, hard-to-remember array configurations 🥱
- Embrace the elegance of Object-Oriented API with Fluent Interface Pattern ⚙️
Installation
Via Composer
composer require figlabhq/crud-resource-for-backpack
Usage
-
Create a new class defining the fields required for your model. Here is how it'd look for standard Laravel User model:
<?php declare(strict_types=1); namespace App\CrudResources; use FigLab\CrudResource\CrudResource; use App\Models\User; use FigLab\CrudResource\Fields\Email; use FigLab\CrudResource\Fields\Password; use FigLab\CrudResource\Fields\Select; use FigLab\CrudResource\Fields\Text; class UserCrudResource extends CrudResource { public function fields(): array { return [ Text::make('Name') ->sortable(), Email::make('Email'), Password::make('Password') ->size(6) ->onlyOnForms(), Password::make('Confirm Password', 'password_confirmation') ->size(6) ->onlyOnForms(), ]; } }
-
In your Crud controller, call the relevant methods:
<?php declare(strict_types=1); namespace App\Http\Controllers; use App\CrudResources\User\UserCrudResource; class UserCrudController extends CrudController { private UserCrudResource $crudResource; public function setup() { $this->crud->setModel(\App\Models\User::class); $this->crud->setRoute(config('backpack.base.route_prefix') . '/users'); $this->crud->setEntityNameStrings('user', 'users'); $this->crudResource = new UserCrudResource($this->crud); } protected function setupListOperation(): void { $this->crudResource->buildList(); } protected function setupCreateOperation(): void { $this->crud->setValidation(UserStoreRequest::class); $this->crudResource->buildCreateForm(); } protected function setupUpdateOperation(): void { $this->crud->setValidation(UserUpdateRequest::class); $this->crudResource->buildUpdateForm(); } }
-
Enjoy a fully-functional CRUD panel 🎉
Documentation
Coming soon...stay tuned 😅
Change log
Changes are documented here on Github. Please see the Releases tab.
Contributing
Please see contributing.md for a todolist and how-tos.
Security
If you discover any security related issues, please email hello@figlab.io instead of using the issue tracker.
Credits
License
This project was released under MIT, so you can install it on top of any Backpack & Laravel project. Please see the license file for more information.
However, please note that you do need Backpack installed, so you need to also abide by its YUMMY License. That means in production you'll need a Backpack license code. You can get a free one for non-commercial use (or a paid one for commercial use) on backpackforlaravel.com.