abdelilahlbardi/laragenerator

This package is abandoned and no longer maintained. No replacement package was suggested.

DRY while building your Laravel projects.

1.5 2017-02-16 12:09 UTC

This package is not auto-updated.

Last update: 2021-02-05 23:53:52 UTC


README

Laravel 5.4 generator

Building a laravel project comes from an idea. So why not to build the main idea behavior and leave the rest to Laragenerator in order to bootstrap your project. This package helps you to focus more about your project idea. DRY.

The current features help you to :

- Create Namespaces.
- Create Controllers.
- Create Form Requests.
- Create Models.
- Create Models Relationships.
- Create Migrations.
- Create Routes Files.
- Create Views files.

If you have any suggestions please let me know : https://github.com/AbdelilahLbardi/Laragenerator/pulls.

Installation

First, pull in the package through Composer.

"require": {
    "laracasts/generators": "master@dev",
    "abdelilahlbardi/laragenerator": "^1.5"
}

And then run :

composer update

After that, include the service provider within config/app.php.

'providers' => [
    AbdelilahLbardi\LaraGenerator\Providers\LaraGeneratorServiceProvider::class,
];

Usage

The package extends Laravel Artisan and add generate:resource command :

Here's a quick example of how to bootstrap your laravel idea:

php artisan generate:resource Backend/Article "titles:string, content:text"
Name Type Exemple Usage
Model Argument Backend/Article Required
Schema Argument --schema="title:string, content:text, slug:string:unique" optional
Relationships Option --relations="hasmany:tags, belongsto:user" optional
Without controller Option --without-controller optional
Without model Option --without-model optional
Without request Option --without-request optional
Without views Option --without-views optional
Without routes Option --without-routes optional
Without migration Option --without-migration optional
Use flash Option --with-flash optional
Rollback Option --rollback optional

Examples

Bootstrapping with all the resources

php artisan generate:resource Article "title:string, content:text, slug:string:unique, user_id:integer:foreign"

You will notice additional files and folders appearing in your project :

  • Controllers/ArticlesController.php : Here your generated controller inside the namespace that you specified.
  • app/Models/Article : New Models folder the your Models.
  • resources/views/articles/index.blade.php : index view which is empty.
  • resources/views/articles/create.blade.php : empty create view.
  • resources/views/articles/edit.blade.php : empty edit view.
  • routes/web/articles.php : Ready routes generated.
  • database/migrations/yyyy-mm-dd-create_articles_table.php : Here your migration.

Bootstrapping without the model

php artisan generate:resource Backed/Item "title:string, price:float, slug:string:unique, category_id:integer:foreign" --without-model

This will generate the same files as the recent command but will no include :

  • Controllers/Backend/ItemsController.php : Here your generated controller inside the namespace that your specified.
  • resources/views/backend/items/index.blade.php : index view which is empty.
  • resources/views/backend/items/create.blade.php : empty create view.
  • resources/views/backend/items/edit.blade.php : empty edit view.
  • routes/web/backend/items.php : Ready routes generated.
  • database/migrations/yyyy-mm-dd-create_items_table.php : Here your migration.

Bootstrapping with empty migration

Since --schema is an optional option, if you don't specify the --schema option, Laragenerator generates an empty model with a simple id and timestamps.

To do so, here's a simple command.

php artisan generate:resource Backed/Item

The migration file will look like:

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateItemsTable extends Migration
{
  /**
   * Run the migrations.
   *
   * @return void
   */
  public function up()
  {
      Schema::create('items', function (Blueprint $table) {
          $table->increments('id');
          
          $table->timestamps();
      });
  }

  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down()
  {
      Schema::drop('items');
  }
}

Rollback

php artisan generate:resource Frontend/User --rollback

With the Laragenerator `--rollback` option, you don't need to delete the generated folders manually. It does all the job for you.

Notice that if you have more controllers this options doesn't delete all the controllers in the namespace.

Templates publishing

You may want to customize the templates like the following artisan command:

php artisan vendor:publish --tag=templates

This will add a new folder to your app called Tempaltes where you will find the following files:

  • Templates/Controller/Controller.txt : Controllers Template.
  • Templates/Model/Model.txt : Models Template.
  • Templates/View/index.txt : Index View Template.
  • Templates/View/headerCell.txt : HTML table element header row Template.
  • Templates/View/contentCell.txt : HTML table element content rows Template.
  • Templates/View/create.txt : Create View Template.
  • Templates/View/createInput.txt : Create form inputs View Template.
  • Templates/View/edit.txt : Edit View Template.
  • Templates/View/editInput.txt : Edit form inputs View Template.
  • Templates/routes.txt: Routes File Tempalte.

Schema

Since Laragenerator uses https://github.com/laracasts/Laravel-5-Generators-Extended to generate migration and schema

you can find the related documentation here: https://github.com/laracasts/Laravel-5-Generators-Extended.