This package allows creating CRUD panels for Backpack for Laravel administration panel using fluent field definitions.
This is heavily inspired by Laravel Nova.
- 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 ⚙️
Via Composer
composer require figlabhq/crud-resource-for-backpack
-
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 🎉
Coming soon...stay tuned 😅
Changes are documented here on Github. Please see the Releases tab.
Please see contributing.md for a todolist and how-tos.
If you discover any security related issues, please email hello@figlab.io instead of using the issue tracker.
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.