Giter Site home page Giter Site logo

emrancu / crud-resource-for-backpack Goto Github PK

View Code? Open in Web Editor NEW

This project forked from figlabhq/crud-resource-for-backpack

0.0 0.0 0.0 20 KB

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

License: MIT License

PHP 100.00%

crud-resource-for-backpack's Introduction

Crud Resource for 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.

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.

crud-resource-for-backpack's People

Contributors

phpfour avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.