Documentation

Last updated: February 24th, 2018

Installation

For installation instructions please follow step by step in Quick Start page

Generator Introduction

Generator Commands

Generator provides various commands to generate scaffold & apis.

Generator Inputs

It is really important how to use generator. Generator supports three methods of input:

  • Input from Console
  • Input from File
  • Input from Table

We will discuss console method here. You can check other options from above links. When you run command, it give following instructions,
Here, you have to insert fields for you models, except id & timestamps (created_at & updated_at) fields. That will be automatically added by generator. When you are done with inserting fields. Type "exit".
When you run any command, it asks for two things:

  • Field Inputs

    Now, let's get started with specifying the field. There is some format in which we have to specify field inputs
    name db_type html_type options

    Here is what this means,

    • name - name of the field (snake_case recommended)
    • db_type - database type. e.g.
      • string - $table->string('field_name')
      • string,25 - $table->string('field_name', 25)
      • text - $table->text('field_name')
      • integer,false,true - $table->integer('field_name',false,true)
      • string:unique - $table->string('field_name')->unique()
      • For foreign keys,
        • integer:unsigned:foreign,table_name,id
        • $table->foreign('field_name')->references('id')->on('table_name')
    • html_type - html field type for forms. e.g.
      • text
      • textarea
      • password

      Here is the full guide for field inputs

    • options - Options to prevent field from being searchable, fillable, display in form & index

      Here are all options by which you can prevent it, these all fields should be passed by comma separated string.

      e.g. s,f,if,ii

      • s - specify to make field non-searchable
      • f - specify to make field non-fillable
      • if - to skip field from being asked in form
      • ii - to skip field from being displayed in index view

    so here are some examples, how field inputs can be passed together

    • title string text
    • body text textarea s,ii
    • email string:unique email
    • writer_id integer:unsigned:foreign,writers,id text s
  • Validations

    In second field you can specify validations for fields from any available validations of laravel. e.g.

    • required
    • min:5
    • email
    • numeric

    Generator also supports various other commands to generate files individually like generating an only model, repository or controller etc. You can find a full doc here.

Generator Config

You can configure paths, namespaces, options, add_ons from published config file (config\infyom\laravel_generator.php).

Paths

migration - path where migration file should be generated

model - path where the model file should be generated

datatables - path where DataTable files should be generated

repository - path where repository file should be generated

routes - path of routes file where routes should be added

api_routes - path of api_routes.php (this file will contain all API routes)

request - path where request file should be generated

api_request - path where API request file should be generated

controller - path where scaffold controller file should be generated

api_controller - path where API controller file should be generated

test_trait - path where test trait file should be generated

repository_test - path where repository test file should be generated

api_test - path where test files should be generated

api_controller - path where API controller file should be generated

test_trait - path where test trait file should be generated

repository_test - path where repository test file should be generated

api_test - path where test files should be generated

views - path where views file should be generated

schema_files - path where all schema files should be stored

templates_dir - path where all templates should be published

Namespaces

model - Namespace of Model

datatables - Namespace of DataTable files

repository - Namespace of Repository

controller - Namespace of scaffold Controller

api_controller - Namespace of API Controller

request - Namespace of scaffold Request

api_request - Namespace of API Request

Scaffold Templates

templates - Scaffold Templates types (core-templates, adminlte-templates, metronic-templates or flatlab-templates)

Model Extend Class

model_extend_class - Model Extends Class

API Routes Prefix & Version

api_prefix - API prefix

api_version - API version

Options

softDelete - use soft delete with models

Prefixes

route - route prefix

path - path prefix

view - view prefix

public - public folder prefix

Add-Ons

swagger - generate swagger annotations for APIs

tests - generate test cases for APIs

datatables - generate CRUD index file with datatables

menu - If you are using generator's default layout then make it true to generate sidebar menu for module

Timestamps

enabled - enable timestamps

created_at - Created At timestamp field name

updated_at - Updated At timestamp field name

deleted_at - Deleted At timestamp field name

Soft Delete

Models can be generated with soft delete option. It is by default false.

You can configure it from config (config/infyom/laravel_generator.php). In order to enable it, set
'options' = > 'softDelete' = > true .

If you want custom delete_at column name then you can specify in config/infyom/laravel_generator.php at
'timestamps' = > 'deleted_at' = > 'custom_deleted_at' .

Swagger

You can also generate swagger annotations for your apis. swagger option is false by default and can be enabled from config.
set :

'add_on.swagger' = > true

Also, in addition, you need to configure jlapp/swaggervel. You can find installation process here

Test Case

You can also generate test cases for your APIs, test generation option is false by default and can be enabled from config.
Here are the full steps to generate test cases:

  1. Set 'add_on.tests' => true in config/laravel_generator.php.
  2. If you have a different test directory then standard laravel one, set the path of your test directory in config file. (config/laravel_generator.php => 'paths' => 'api_tests' => {your_test_directory). Otherwise you can just skip this step.
  3. Run an artisan command php artisan infyom.publish:tests. It will generate a ApiTestTrait.php into your tests directory.
  4. Add trait file and directory file to your composer.json,
  5. Run composer dump-autoload

Generator Command

The Generator has various commands to generate files in a group or individually. Sometimes you need to generate/re-generate individual files after making some manual changes to some files and you don't want the generator to override your changes. Also, it has command to rollback all generated files.

Rollback Command

To rollback, we have the following command,

Where,
{ModelName} - Its a model name for which you want to delete files
{COMMAND_TYPE} - Command type from api, scaffold or api_scaffold

Migration Generator

Repository Generator

API Controller Generator

API Request Generator

Test Generator

Scaffold Controller Generator

Scaffold Request Generator

View Generator

Scaffold Generator Option

Paginate Option

To paginate records, you can use --paginate option to command. e.g.

Datatables Option

The Generator also has the ability to generate CRUD file with datatables. To enable datatables option, you need to install yajra/laravel-datatables package.
You can find full installation steps here.
Make sure you install right datatables version based on its compatibility.
Following versions are supported by Generator:

Generator/Laravel Version DataTables Version
5.1 6.x
5.2 6.x
5.3 6.x
5.4 6.x
5.5 8.x

You need to install Datatables and Buttons plugin as well, if you are using version 8.x.
Datatables can be configured from config. Once, you are done with installation. Make 'add_on.datatables' => true in config/webcore/laravel_generator.php.
But Generator also gives option to override the option on the fly while generating files.
You can specify --datatables=true OR --datatables=false to override configured value of Datatable.

View Option

While generating views, if you don't want to generate all views again. Then you can pass an option --views. For example,
You can specify any of these values and only that view files will be generated.

php artisan generate:scaffold {ModelName} --views=index,create,edit,show

Save Model Schema

The Generator also has an option to save model schema to json file, so it can be used in future and don't need to re-enter the whole schema from the console.
Schema folder can be configured in config. set 'path' => 'schema_files' => 'folder_path'. Pass --save option to command to save file,

Fields from File

If you have schema files stored then it can be used with generator rather than entering schema from the console.
To use schema file, use --fieldsFile option.
Here is the definition and possible options for schema field:
You can also define relationship in field as following:
Some relationships, like One to Many do not have a local field in current model, but some other model contains its primary key as foreign key. In such cases, you can define relationship by following definition:

Custom Table Name

You can also specify your own custom table name by

Generate From Table

Custom Primary Key Name

By default, Generator takes the primary key as id field. But is also gives you the flexibility to use your own primary key field name via --primary option.

Prefix Option

Sometimes, you don't want to directly generate the files into configured folder but in a subfolder of it. Like, admin and that subfolder should be created with namespaces in all generated files. Then you can use --prefix=admin option.

Skip File Generation

The Generator also gives the flexibility to choose what you want to generate or what you want to skip. While using generator command, you can specify skip option to skip files which will not be generated.

You can specify any file from the following list:

  • migration
  • model
  • controllers
  • api_controller
  • scaffold_controller
  • scaffold_requests
  • routes
  • api_routes
  • scaffold_routes
  • views
  • tests
  • menu
  • dump-autoload

Field Definition

HTML Type

While passing htmlType in a field, we have different syntax for different fields. Here is the full guide for each supported field.

Supported HTML Input Types & Formats Valid Examples
text text
textarea textarea
email email
date date
number number
password password
file (partially supported) file
select
select,value1,value2,value3
select,label1:value1,label2:value2,label3:value3

select,Daily,Weekly,Monthly
select,Sunday:0,Monday:1,Tuesday:2
checkbox
checkbox,value
checkbox
checkbox,yes
checkbox,1
radio
radio,label1,label2
radio,label1:value1,label2:value2

radio,Male,Female
radio,Yes:1,No:0

API Generator Option

API Parameters

API Generator has a bunch of options and parameters. Following parameters are supported with index API.

  • limit : Limit the number of returned results
  • search : Global search on all searchable fields
  • offset : Offset from where results should be returned
  • sortedBy : Sort result by given field

Page Templating

Component Presentation

Elogui - Datasource

Personalization (BETA)