Giter Site home page Giter Site logo

fhferreira / laravel-api-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mitulgolakiya/laravel-api-generator

0.0 1.0 0.0 107 KB

Laravel API/Scaffold/CRUD Generator including Controller, Repository, Model, Migrations, routes.php update.

License: MIT License

PHP 100.00%

laravel-api-generator's Introduction

Laravel API/Scaffold/CRUD Generator (Laravel5)

Total Downloads

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.

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.

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

And your simple CRUD API is ready in mere seconds.

Here is the full documentation.

Steps to Get Started

  1. Add this package to your composer.json:

     "require": {
         "mitulgolakiya/laravel-api-generator": "dev-master"
     }
    
  2. Run composer update

     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.

     '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.

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

     php artisan vendor:publish --provider='Mitul\Generator\GeneratorServiceProvider'
    
  2. Fire the artisan command to generate API for Model, or to generate scaffold with views for web applications

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

    e.g.

     php artisan mitul.generator:api Project
     php artisan mitul.generator:api Post
    
     php artisan mitul.generator:scaffold Project
     php artisan mitul.generator:scaffold Post
    
  3. Enter the fields with options

  4. And you are ready to go. :)

Documentation

Generator Config file

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

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_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)

namespace_model - Namespace of Model
namespace_repository - Namespace of Repository
namespace_controller - Namespace of Controller
namespace_request - Namespace for Request

Field Input

Here is the input for the fields by which you can specify Input.

    fieldName:fieldType,options:fieldOptions

e.g.,

    email:string:unique
    email:string:unique,default('[email protected]')
    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.

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.

Success

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

data can be anything as per response.

Failure

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

data will be optional. And code will be error code.

Generated Views

While generating scaffold, all views are created with basic CRUD functionality. (currently delete is not working)

Views will be created in resources/views/modelName folder,

    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] (http://drive.google.com/uc?export=view&id=0B5kWGBdVjC7RbTRvTEswQ0tfOEU)

Generated Files & routes.php

![Image of Generated Files] (http://drive.google.com/uc?export=view&id=0B5kWGBdVjC7RZ1VMcXlsM1Z2MDg)

Migration File

![Image of Migration File] (http://drive.google.com/uc?export=view&id=0B5kWGBdVjC7RMWtnN1RxUzdmTUE)

Model File

![Image of Model File] (http://drive.google.com/uc?export=view&id=0B5kWGBdVjC7RRUJfdHE4MVRaeXM)

Repository File

![Image of Repository File] (http://drive.google.com/uc?export=view&id=0B5kWGBdVjC7ROUdNVTVORm5nQ1E)

Controller File

![Image of Controller File] (http://drive.google.com/uc?export=view&id=0B5kWGBdVjC7RREVacVlOZDhxNDQ)

View Files

![Image of View Files] (http://drive.google.com/uc?export=view&id=0B5kWGBdVjC7RQW5FOXExOFhEbms)

Credits

This API Generator is created by Mitul Golakiya.

Bugs & Forks are welcomed :)

laravel-api-generator's People

Contributors

ericlbarnes avatar mitulgolakiya 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.