Skip to content

Fluent Interface for Laravel Backpack - Define resources once and get all CRUD configurations ready!

License

Notifications You must be signed in to change notification settings

figlabhq/crud-resource-for-backpack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CRUD Resource for Laravel Backpack

Latest Version on Packagist Total Downloads The Whole Fruit Manifesto

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

  1. 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(),
            ];
        }
    }
  2. 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();
        }
    }
  3. Enjoy a fully-functional CRUD panel 🎉

    User Listing

    User Create/Update

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 [email protected] 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.

About

Fluent Interface for Laravel Backpack - Define resources once and get all CRUD configurations ready!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages