Coder Social home page Coder Social logo

laragenerator's Introduction

Laragenerator

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 are :

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

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:resources 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 appear in your project :

  • Controllers/AriclesController.php : Here your generated controller inside the namespace that your specified.
  • app/Models/Aritlce : 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/AriclesController.php : Here your generated controller inside the namespace that your specified.
  • resources/views/backend/articles/index.blade.php : index view which is empty.
  • resources/views/backend/articles/create.blade.php : empty create view.
  • resources/views/backend/articles/edit.blade.php : empty edit view.
  • routes/web/backend/articles.php : Ready routes generated.
  • database/migrations/yyyy-mm-dd-create_articles_table.php : Here your migration.

Bootstrapping with empty migration

Since --schema is an optional option, if you don't specify the --schema option, Laragenerator generate 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 looks 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 to your app a new folder 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 its documentation here: https://github.com/laracasts/Laravel-5-Generators-Extended to know more about what to fill in `--schema` option.

laragenerator's People

Contributors

abdelilahlbardi avatar

Watchers

 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.