API Generator Options

Supported API Params

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

Swagger

After adding packages, run the following command:

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 Cases Generation

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.
"autoload-dev": {
    "classmap": [
        "tests/TestCase.php",
        "tests/ApiTestTrait.php",
        "tests/traits"
    ]
}
  1. Run composer dump-autoload

Scaffold Options

Paginate Records

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

php artisan infyom:api $MODEL_NAME --paginate=10

Datatables

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.

Once, you are done with installation. Make 'add_on.datatables' => true inconfig/infyom/laravel_generator.php.

Datatables from CLI

Datatables can be configured from config 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.

php artisan infyom:scaffold $MODEL_NAME --datatables=true

Generate Only Specified Views

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 infyom:scaffold $MODEL_NAME --views=index,create,edit,show

Generator Options

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

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.

php artisan infyom:scaffold $MODEL_NAME --save

Fields From File

If you have schema files stored then it can be used with generator rather than entering schema from the console.

You can find a sample file at vendor\infyom\laravel-generator\samples\fields_sample.json.

To use schema file, use --fieldsFile option.

php artisan infyom:scaffold $MODEL_NAME --fieldsFile=absolute_file_path_or_path_from_base_directory

Here is the definition and possible options for schema field:

{
    "fieldInput": "title:string,20",    // field name with database type and options
    "htmlType": "text",                 // field html type
    "validations": "required",          // field validations
    "searchable": false,                // is field searchable
    "fillable": false,                  // if field should be fillable
    "primary": true,                    // does field is primary key
    "inForm": false,                    // if field should be included in create and edit form
    "inIndex": false                    // if field should be included in index.blade.php
}

Custom Table Name

You can also specify your own custom table name by,

php artisan infyom:scaffold $MODEL_NAME --tableName=custom_table_name

Generate From Table

php artisan infyom:scaffold $MODEL_NAME --fromTable --tableName=$TABLE_NAME

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.

php artisan infyom:api_scaffold Post --skip=routes,migration,model

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

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.

php artisan infyom:scaffold $MODEL_NAME --primary=custom_name_id

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.

php artisan infyom:scaffold $MODEL_NAME --prefix=admin

results matching ""

    No results matching ""