bgaze/laravel-crud

A CRUD generator for Laravel 5.5+

1.0.1 2019-04-16 13:47 UTC

This package is auto-updated.

Last update: 2024-11-08 23:39:55 UTC


README

Table of content

The Conventions section explain very important concepts.
Please read it carrefully before using this package.

Documentation:

Overview

This package allows to generate CRUDs in a breath for your Laravel 5.5+ applications.
Please have a look to this short video on Vimeo to see it in action.

Using the SignedInput syntax, it offers a concise and handy way to define the model fields.

It is designed to create easily custom CRUDs, aka themes.

Two simple themes are provided :

  • crud:classic generates a fully fonctionnal "classic" CRUD.
    It creates for you : migration, model, factory, seeder, request, resource, controller, blade views and routes.
  • crud:api generates a fully fonctionnal REST API CRUD.
    It creates for you : migration, model, factory, seeder, request, resource, controller and routes.

Installation

Simply import the package as a dev dependency into your Laravel application:

composer require --dev bgaze/laravel-crud

You can publish the package configuration to /config/crud.php:

php artisan vendor:publish --provider=Bgaze\Crud\ServiceProvider

And classic themes views to /resources/views/vendor/crud-classic:

php artisan vendor:publish --tag=crud-classic-views

Why this package?

Laravel is my favorite PHP framework.
But using it daily, at work and for my private projects, I realized that each time I create a model, I was wasting a lot of time doing repetitive tasks instead of really working on the application itself:

  1. Generate classes: model, migration, controller, request, factory, seeder, ...
  2. Define the table fields into migration.
  3. Create the rules into the request class.
  4. Create the model faker into factory.
  5. Define CRUD actions into controller.
  6. Register controller routes.
  7. Create CRUD views and model forms.

I believe that this process can be automated a lot to produce a generic functionnal CRUD that we just need to customize, keeping the focus on the application logic.

The key for that is to define the Model table fields from whom, sticking to the framework conventions, a lot of things can be deducted.
For instance request rules or form fields: a non-nullable field is required, an enum field is often a select.

But even if CRUD generation logic will be almost the same, the files to generate can vary a lot depending on the tools used.
For instance, using classic HTML or Vue.js, a CRUD files will be very different.

So this package goals are to provide:

  • A handy way to define required informations for a CRUD generation.
  • An extensible base to create easily custom CRUD generators (named themes).
  • Two simple themes to use as base for custom CRUDs:
    • A REST API CRUD.
    • A standart CRUD using Blade templates.

Conventions

CRUD generator need to manipulate Model name in order to generate required ressources.
As a convention, we designate by:

  • FullName: the model's name including namespace without the App part.
  • Plural: the FullName with last segment pluralized.
  • Plurals: the FullName with each segments pluralized.

Examples:

Models:
    \App\MyGrandParent  
    \App\MyGrandParent\MyParent  
    \App\MyGrandParent\MyParent\MyChild

FullName:
    MyGrandParent  
    MyGrandParent\MyParent  
    MyGrandParent\MyParent\MyChild

Plural:
    MyGrandParents  
    MyGrandParent\MyParents  
    MyGrandParent\MyParent\MyChildren

Plurals:
    MyGrandParents  
    MyGrandParents\MyParents  
    MyGrandParents\MyParents\MyChildren