PHP Classes
elePHPant
Icontem

Laravel CRUD Generator: Generate MVC classes for any Laravel model

Recommend this page to a friend!
  Info   View files Documentation   View files View files (105)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-11-12 (2 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
laravel-crud 1.0GNU General Publi...7PHP 5, Libraries, Code Generation, De...
Description Author

This package can generate MVC classes for any Laravel model.

It can read the definitions from a configuration and generates for views, Web and API controllers for a given model.

The configuration can define details for what should be generated for one or more models, including how to show properties or not in forms, validation rules, etc..

Name: TJ Webb <contact>
Classes: 1 package by
Country: Canada Canada

 

Details

Laravel Crud

Laravel Crud is a package for automatically adding CRUD (Create, Read, Update, Delete) views, web controllers and API controllers for any model as rapidly as possible.

Prototyping

Laravel Crud let's you quickly create all of the views and controllers you need for the full CRUD operation set (create, read, update, delete), including an index with just a configuration file. Laravel Crud also creates and registers routes for you automatically, giving you both web and API endpoints for your models with as little as one line in an array.

The intent of Laravel Crud is for rapid prototyping. All you need for your complete CRUD operation set is a model and corresponding database table. The properties and their types are read from the database and the appropriate UI controlls are rendered in the web UIs.

Installation

Install via composer.

composer require webbtj/crud

Usage

Once installed you'll want to publish a config file to edit.

php artisan vendor:publish

When prompted, select crud-config. This will create config/crud.php where you can define the models you want crud functionality generated for.

Configuration

You can list any models you want crud functionality for in the config/crud.php configuration file. This file returns an array, each element in the array can be either a string naming a model, or an array with additional configuration options such as which fields are read only, excluded from certain views, and even validation. When specifying the model name, you can include the full namespace of the model (App\Employee) or simply the name of the class itself (Employee). The model name is also case-insensitive.

Example configuration file:

return [
    'models' => [
        // Add your model class names here (full namespace)
        // Exmaple: "App\\Employee"

        "App\\SmallChild", // a string that will create all routing and views
                           // for the model with all defaults.

        [
            'model' => "App\\FastCar", // specify the model with extra configs
            'index' => [
                'exclude' => ['created_at'], // don't show this property in the
                                             // index view
            ],
            'store' => [
                'validation' => [ // run this validation on the "store" method
                    'year' => 'required'
                ],
            ],
        ],

        [
            'model' => "App\\Employee",
            'show' => [
                'exclude' => ['sample_text', 'sample_string'],
            ],
            'edit' => [
                'exclude' => ['sample_longText'],
                'readonly' => ['sample_char'], // in the edit interface, show
                                               // this property but make it
                                               // read only
            ],
            'create' => [
                'exclude' => ['sample_text'],
                'include' => ['updated_at'], // include this property in the
                                             // create interface (it's normally
                                             // not included)
                'readonly' => ['sample_integer'],
            ],
            'index' => [
                'include' => [
                    'id', 'first_name', 'last_name', 'email', 'sample_json',
                    'sample_jsonb', 'sample_enum', 'sample_set', 'enabled'
                ],
            ],
            'update' => [
                'validation' => [
                    'first_name' => 'required',
                    'last_name' => 'required',
                ],
            ]
        ]
    ]
];

You can specify include, exclude, and readonly arrays of properties for each of the four standard views, show, edit, create, and index. You can also specify include, exclude, and validation arrays for each of the two standard methods, store and update. If you're specifying additional options in an array format, you must include the model definition as well.

Defaults

While you have complete control over what fields are displayed and can be edited, there are defaults that the package will fall back to when you do not provide specifics. By default...

  • no validation is applied to any properties
  • id, created_at, and updated_at are not updateable via requests
  • each view will display all properties

In all views except index, you will exclude fields you don't want displayed. If you want to customize the index view you will need to include each property.

Production

But reading schemas for every interaction with a model, reading and parsing all of these inclusion, exclusion, read-only, and validation rules from a config, these are all pretty expensive operations and not really suited for production apps. That's why there's an artisan command to commit views and controllers to _your_ codebase for better performance and further development control.

php artisan crud:publish

The crud:publish artisan command will create a directory for the model in your views directory with index, show, create, and edit views. It will also create a web controller in your Http/Controllers directory and an API controller in your Http/Controllers/Api directory. Finally it will provide recommended code for adding the routes to your web.php and api.php routes files, and recommend that you now remove the publish model(s) from your crud.php config file.

Of course you can customize and limit this publish with options. Provide --model= to speficfy the model you wish to publish. Omitting this option will publish all models. This option allows for multiple values simply by specifying it more than once (Example: `php artisan crud:publish --model=Employee --model=Car).

You can also specify which elements you want published by specifying --type=. Like --model= this can be repeated to specify multiple types to publish. The valid types are as follows:

  • controller - publishes the web controller
  • api.controller - publishes the API controller
  • views - publishes all views
  • view.index - publishes just the index view
  • view.show - publishes just the show view
  • view.create - publishes just the create view
  • view.edit - publishes just the edit view

Some notes on these options. They are case insensitive; all punctuation is stripped out (so api.controller, api-controller, and apicontroller all work); singular vs plural doesn't matter (English only); and the order of words for the specific views doesn't matter (view.index or index.view).

Roadmap

  • Unit testing
  • Beta release/release to Packagist.

Contributing

Contributions are always welcome on GitHub. Please open issues before submitting PRs and do tag the issue in your commit messages/PR description. Also, please adhere to PSR-2 as much as possible.

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file, 7 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file license Lic. License text
Accessible without login Plain text file readme.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageCommands (1 file)
Files folder imageconfig (1 file)
Files folder imageHttp (1 directory)
Files folder imagestubs (2 files, 1 directory)
Files folder imageTraits (2 files)
Files folder imageutilities (4 files)
Files folder imageviews (1 directory)
  Plain text file CrudServiceProvider.php Class Class source

  Files folder image Files  /  src  /  Commands  
File Role Description
  Plain text file Publisher.php Class Class source

  Files folder image Files  /  src  /  config  
File Role Description
  Accessible without login Plain text file crud.php Aux. Auxiliary script

  Files folder image Files  /  src  /  Http  
File Role Description
Files folder imageControllers (3 files)

  Files folder image Files  /  src  /  Http  /  Controllers  
File Role Description
  Plain text file CrudApiController.php Class Class source
  Plain text file CrudBaseController.php Class Class source
  Plain text file CrudWebController.php Class Class source

  Files folder image Files  /  src  /  stubs  
File Role Description
Files folder imageviews (5 files, 1 directory)
  Plain text file ApiController.php.stub Class Class source
  Plain text file WebController.php.stub Class Class source

  Files folder image Files  /  src  /  stubs  /  views  
File Role Description
Files folder imagepartials (5 files, 1 directory)
  Accessible without login Plain text file create.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file edit.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file index.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file layout.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file show.blade.php.stub Data Auxiliary data

  Files folder image Files  /  src  /  stubs  /  views  /  partials  
File Role Description
Files folder imagefields (4 directories)
  Accessible without login Plain text file create-column.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file edit-column.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file index-column.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file index-header.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file show-column.blade.php.stub Data Auxiliary data

  Files folder image Files  /  src  /  stubs  /  views  /  partials  /  fields  
File Role Description
Files folder imagecreate (15 files)
Files folder imageedit (15 files)
Files folder imageindex (4 files)
Files folder imageshow (3 files)

  Files folder image Files  /  src  /  stubs  /  views  /  partials  /  fields  /  create  
File Role Description
  Accessible without login Plain text file array-option.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file array.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file boolean.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file date.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file datetime.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file decimal.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file enum-option.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file enum.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file float.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file integer.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file json.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file string.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file text.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file time.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file _readonly.blade.php.stub Data Auxiliary data

  Files folder image Files  /  src  /  stubs  /  views  /  partials  /  fields  /  edit  
File Role Description
  Accessible without login Plain text file array-option.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file array.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file boolean.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file date.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file datetime.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file decimal.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file enum-option.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file enum.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file float.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file integer.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file json.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file string.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file text.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file time.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file _readonly.blade.php.stub Data Auxiliary data

  Files folder image Files  /  src  /  stubs  /  views  /  partials  /  fields  /  index  
File Role Description
  Accessible without login Plain text file array.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file boolean.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file json.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file _general.blade.php.stub Data Auxiliary data

  Files folder image Files  /  src  /  stubs  /  views  /  partials  /  fields  /  show  
File Role Description
  Accessible without login Plain text file boolean.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file json.blade.php.stub Data Auxiliary data
  Accessible without login Plain text file _general.blade.php.stub Data Auxiliary data

  Files folder image Files  /  src  /  Traits  
File Role Description
  Plain text file CrudControllerTrait.php Class Class source
  Plain text file PublisherTrait.php Class Class source

  Files folder image Files  /  src  /  utilities  
File Role Description
  Plain text file EnumType.php Class Class source
  Plain text file Field.php Class Class source
  Accessible without login Plain text file helpers.php Example Example script
  Plain text file Util.php Class Class source

  Files folder image Files  /  src  /  views  
File Role Description
Files folder imagecrud (5 files, 1 directory)

  Files folder image Files  /  src  /  views  /  crud  
File Role Description
Files folder imagefields (3 directories)
  Accessible without login Plain text file create.blade.php Aux. Auxiliary script
  Accessible without login Plain text file edit.blade.php Aux. Auxiliary script
  Accessible without login Plain text file index.blade.php Aux. Auxiliary script
  Accessible without login Plain text file layout.blade.php Aux. Auxiliary script
  Accessible without login Plain text file show.blade.php Aux. Auxiliary script

  Files folder image Files  /  src  /  views  /  crud  /  fields  
File Role Description
Files folder imageedit (12 files)
Files folder imageindex (12 files)
Files folder imageshow (12 files)

  Files folder image Files  /  src  /  views  /  crud  /  fields  /  edit  
File Role Description
  Accessible without login Plain text file array.blade.php Aux. Auxiliary script
  Accessible without login Plain text file boolean.blade.php Aux. Auxiliary script
  Accessible without login Plain text file date.blade.php Aux. Auxiliary script
  Accessible without login Plain text file datetime.blade.php Aux. Auxiliary script
  Accessible without login Plain text file decimal.blade.php Aux. Auxiliary script
  Accessible without login Plain text file enum.blade.php Aux. Auxiliary script
  Accessible without login Plain text file float.blade.php Aux. Auxiliary script
  Accessible without login Plain text file integer.blade.php Aux. Auxiliary script
  Accessible without login Plain text file json.blade.php Aux. Auxiliary script
  Accessible without login Plain text file string.blade.php Aux. Auxiliary script
  Accessible without login Plain text file text.blade.php Aux. Auxiliary script
  Accessible without login Plain text file time.blade.php Aux. Auxiliary script

  Files folder image Files  /  src  /  views  /  crud  /  fields  /  index  
File Role Description
  Accessible without login Plain text file array.blade.php Aux. Auxiliary script
  Accessible without login Plain text file boolean.blade.php Aux. Auxiliary script
  Accessible without login Plain text file date.blade.php Aux. Auxiliary script
  Accessible without login Plain text file datetime.blade.php Aux. Auxiliary script
  Accessible without login Plain text file decimal.blade.php Aux. Auxiliary script
  Accessible without login Plain text file enum.blade.php Aux. Auxiliary script
  Accessible without login Plain text file float.blade.php Aux. Auxiliary script
  Accessible without login Plain text file integer.blade.php Aux. Auxiliary script
  Accessible without login Plain text file json.blade.php Aux. Auxiliary script
  Accessible without login Plain text file string.blade.php Aux. Auxiliary script
  Accessible without login Plain text file text.blade.php Aux. Auxiliary script
  Accessible without login Plain text file time.blade.php Aux. Auxiliary script

  Files folder image Files  /  src  /  views  /  crud  /  fields  /  show  
File Role Description
  Accessible without login Plain text file array.blade.php Aux. Auxiliary script
  Accessible without login Plain text file boolean.blade.php Aux. Auxiliary script
  Accessible without login Plain text file date.blade.php Aux. Auxiliary script
  Accessible without login Plain text file datetime.blade.php Aux. Auxiliary script
  Accessible without login Plain text file decimal.blade.php Aux. Auxiliary script
  Accessible without login Plain text file enum.blade.php Aux. Auxiliary script
  Accessible without login Plain text file float.blade.php Aux. Auxiliary script
  Accessible without login Plain text file integer.blade.php Aux. Auxiliary script
  Accessible without login Plain text file json.blade.php Aux. Auxiliary script
  Accessible without login Plain text file string.blade.php Aux. Auxiliary script
  Accessible without login Plain text file text.blade.php Aux. Auxiliary script
  Accessible without login Plain text file time.blade.php Aux. Auxiliary script

 Version Control Unique User Downloads  
 100%
Total:0
This week:0