2017 © Pedro Peláez
 

library laravel5-api-generator

Laravel API/Scaffold/CRUD Generator from just one command with including Controller, Repository, Model, Migrations, routes.php update.

image

aziz/laravel5-api-generator

Laravel API/Scaffold/CRUD Generator from just one command with including Controller, Repository, Model, Migrations, routes.php update.

  • Friday, April 3, 2015
  • by aziz
  • Repository
  • 1 Watchers
  • 2 Stars
  • 56 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 153 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Laravel API/Scaffold/CRUD Generator (Laravel5)

Total Downloads, (*1)

I enjoy creating API's and I have worked on many projects that required them. But the problem I always faced was setting up all the boilerplate code. For example each end point needs a migration, model, controller, repository, and on and on. I wanted a way to streamline this process and that is how this package was born., (*2)

This API generator allows you to use artisan commands to automatically generate all these files saving you time. Not only does it auto generate the files but it will set the namespaces., (*3)

The artisan command can generate the following items: * Migration File * Model * Repository (optional) * Controller * View * index.blade.php * show.blade.php * create.blade.php * edit.blade.php * fields.blade.php * adjusts routes.php, (*4)

And your simple CRUD API is ready in mere seconds., (*5)

Here is the full documentation., (*6)

Upgrade Guide from 1.0 to 1.1 or 1.2

  1. Take a backup of your config/generator.php, (*7)

  2. Delete your config/generator.php, (*8)

  3. Change version in composer.json, (*9)

    "require": {
        "mitulgolakiya/laravel-api-generator": "1.2.*"
    }
  4. Run composer update., (*10)

  5. Run publish command again., (*11)

    php artisan vendor:publish --provider="Mitul\Generator\GeneratorServiceProvider"
  6. Replace your custom paths again in config/generator.php., (*12)

  7. Enjoy Upgrade :), (*13)

Steps to Get Started

  1. Add this package to your composer.json:, (*14)

    "require": {
        "mitulgolakiya/laravel-api-generator": "1.2.*"
    }
  2. Run composer update, (*15)

    composer update
  3. Add the ServiceProviders to the providers array in config/app.php.
    As we are using these two packages illuminate/html & laracasts/flash as a dependency.
    so we need to add those ServiceProviders as well., (*16)

    'Illuminate\View\ViewServiceProvider',
    'Illuminate\Html\HtmlServiceProvider',
    'Laracasts\Flash\FlashServiceProvider',
    'Mitul\Generator\GeneratorServiceProvider'

Also for convenience, add these facades in alias array in config/app.php., (*17)

    'Form'  => 'Illuminate\Html\FormFacade',
    'HTML'  => 'Illuminate\Html\HtmlFacade',
    'Flash' => 'Laracasts\Flash\Flash'
  1. Publish generator.php, (*18)

    php artisan vendor:publish --provider="Mitul\Generator\GeneratorServiceProvider"
  2. Fire artisan command to generate API, Scaffold with CRUD views or both API as well as CRUD views., (*19)

    php artisan mitul.generator:api ModelName
    php artisan mitul.generator:scaffold ModelName
    php artisan mitul.generator:scaffold_api ModelName

    e.g., (*20)

    php artisan mitul.generator:api Project
    php artisan mitul.generator:api Post
    
    php artisan mitul.generator:scaffold Project
    php artisan mitul.generator:scaffold Post
    
    php artisan mitul.generator:scaffold_api Project
    php artisan mitul.generator:scaffold_api Post
  3. Enter the fields with options
    , (*21)

  4. And you are ready to go. :), (*22)

Documentation

Generator Config file

Config file (config/generator.php) contains path for all generated files, (*23)

path_migration - Path where Migration file to ge generated
path_model - Path where Model file to ge generated
path_repository - Path where Repository file to ge generated
path_controller - Path where Controller file to ge generated
path_api_controller - Path where API Controller file to ge generated
path_views - Path where views will be created
path_request - Path where request file will be created
path_routes - Path of routes.php (if you are using any custom routes file)
, (*24)

namespace_model - Namespace of Model
namespace_repository - Namespace of Repository
namespace_controller - Namespace of Controller
namespace_api_controller - Namespace of API Controller
namespace_request - Namespace for Request
, (*25)

model_extend - Use custom Model extend
model_extend_namespace - Namespace of custom extended model
model_extend_class - Class name to extend
, (*26)

api_prefix - API Prefix, (*27)

Field Input

Here is the input for the fields by which you can specify Input., (*28)

    fieldName:fieldType,options:fieldOptions

e.g.,, (*29)

    email:string:unique
    email:string:unique,default('me@mitul.me')
    title:string,100
    price:flat,8,4

Parameters will be in the same sequence as Blueprint class function for all types. Option will be printed as it is given in input except unique & primary., (*30)

API Response Structure

Remember: This response structure is based on the most of my API response structure, you can change it to your API response after file generation in controller., (*31)

Success, (*32)

    {
        "flag":true,
        "message":"success message",
        "data":{}
    }

data can be anything as per response., (*33)

Failure, (*34)

    {
        "flag":false,
        "message":"failure message",
        "code": 0
        "data":{}
    }

data will be optional. And code will be error code., (*35)

Generated Views

While generating scaffold, all views are created with basic CRUD functionality., (*36)

Views will be created in resources/views/modelName folder,, (*37)

    index.blade.php - Main Index file for listing records
    create.blade.php - To insert a new record
    edit.blade.php - To edit a record
    fields.blade.php - Common file of all model fields, which will be used create and edit record
    show.blade.php - To display a record

Screenshots

Command Execution

Image of Command Execution, (*38)

Generated Files & routes.php

Image of Generated Files, (*39)

Migration File

Image of Migration File, (*40)

Model File

Image of Model File, (*41)

Repository File

Image of Repository File, (*42)

Controller File

Image of Controller File, (*43)

View Files

Image of View Files, (*44)

Credits

This API Generator is created by Mitul Golakiya., (*45)

Bugs & Forks are welcomed :), (*46)

The Versions

03/04 2015

1.2.x-dev

1.2.9999999.9999999-dev

Laravel API/Scaffold/CRUD Generator from just one command with including Controller, Repository, Model, Migrations, routes.php update.

  Sources   Download

MIT

The Requires

 

by Mitul Golakiya

laravel api crud generator migration model scaffold

03/04 2015

v1.2.3

1.2.3.0

Laravel API/Scaffold/CRUD Generator from just one command with including Controller, Repository, Model, Migrations, routes.php update.

  Sources   Download

MIT

The Requires

 

by Mitul Golakiya

laravel api crud generator migration model scaffold

03/04 2015

v1.2.2

1.2.2.0

Laravel API/Scaffold/CRUD Generator from just one command with including Controller, Repository, Model, Migrations, routes.php update.

  Sources   Download

MIT

The Requires

 

by Mitul Golakiya

laravel api crud generator migration model scaffold

02/04 2015

v1.2.1

1.2.1.0

Laravel API/Scaffold/CRUD Generator from just one command with including Controller, Repository, Model, Migrations, routes.php update.

  Sources   Download

MIT

The Requires

 

by Mitul Golakiya

laravel api crud generator migration model scaffold

30/03 2015

dev-master

9999999-dev

Laravel API/Scaffold/CRUD Generator from just one command with including Controller, Repository, Model, Migrations, routes.php update.

  Sources   Download

MIT

The Requires

 

by Mitul Golakiya

laravel api crud generator migration model scaffold

30/03 2015

v1.2.0

1.2.0.0

Laravel API/Scaffold/CRUD Generator from just one command with including Controller, Repository, Model, Migrations, routes.php update.

  Sources   Download

MIT

The Requires

 

by Mitul Golakiya

laravel api crud generator migration model scaffold

27/03 2015

1.1.x-dev

1.1.9999999.9999999-dev

Laravel API/Scaffold/CRUD Generator from just one command with including Controller, Repository, Model, Migrations, routes.php update.

  Sources   Download

MIT

The Requires

 

by Mitul Golakiya

laravel api crud generator migration model scaffold

27/03 2015

v1.1.0

1.1.0.0

Laravel API/Scaffold/CRUD Generator from just one command with including Controller, Repository, Model, Migrations, routes.php update.

  Sources   Download

MIT

The Requires

 

by Mitul Golakiya

laravel api crud generator migration model scaffold

23/03 2015

v1.0

1.0.0.0

Laravel API/Scaffold/CRUD Generator from just one command with including Controller, Repository, Model, Migrations, routes.php update.

  Sources   Download

MIT

The Requires

 

by Mitul Golakiya

laravel api crud generator migration model scaffold