Skip to content

Generator Options

Legacy Generator Options Docs

Click Here for docs for laravel-generator version < 5.0.

API Generator Options

You can use following options in API Generator.

Supported API Params

API Generator has 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

InfyOm Generator also generate swagger annotations for your apis.

For that, you need to install two packages. Add the following code to your composer.json

sh
"require": {
   "darkaonline/l5-swagger": "8.*",
   "infyomlabs/swagger-generator": "^3.0"
}

After that run the following commands,

sh
composer update
php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"

Swagger option is false by default. It needs to be enabled from config config/laravel_generator.php.

sh
'options' => [
    'swagger' => true, // generate swagger for your APIs
],

Now for all of your APIs, Generator will generate the swagger docs. Once you are done with generation, run the following command.

sh
php artisan l5-swagger:generate

You need to run this command everytime when you generate new APIs or modify existing APIs.

It will generate swagger file for swagger UI on the path storage/api-docs/api-docs.json. To access the swagger UI, open the url /api/documentation and you should be able to see all the api docs.

Test Cases

Test cases for your APIs will be also generated when test generation option is true which is a default value in config. You can make it false, if you do not want to generate it.

sh
'options' => [
    'tests' => true, // generate test cases for your APIs
],

Table Types

Table Type option can be controlled from the config file. There are three possible types for Tables.

Blade

sh
'tables' => 'blade',

Blade option generates very simple HTML Table.

Datatables

sh
'tables' => 'datatables',

With this option the generator generate Table with DataTables. To use this option, you need to install yajra/laravel-datatables package. You can find a full installation steps here.

Make sure you install right datatables version based on its compatibility. If you are using version 8.x or later install Buttons plugin and HTML plugin as well.

Here are the commands that you can follow for the latest version of laravel,

sh
composer require yajra/laravel-datatables-oracle:^10.0
composer require yajra/laravel-datatables-buttons:^9.0 yajra/laravel-datatables-html:^9.0
php artisan vendor:publish --tag=datatables-buttons --force

Then you need to run the command to publish the needed files for CRUD,

sh
php artisan infyom.publish:tables datatables

It will generate the following two views files,

sh
layouts/datatables_css.blade.php
layouts/datatables_js.blade.php

You are all set to generate CRUD with DataTables.

Livewire Tables

sh
'tables' => 'livewire',

For Livewire Table Types, generator uses rappasoft/laravel-livewire-tables for generate CRUD.

For that, we need to install the above package with the following commands,

sh
composer require rappasoft/laravel-livewire-tables
php artisan vendor:publish --provider="Rappasoft\LaravelLivewireTables\LaravelLivewireTablesServiceProvider" --tag=livewire-tables-config
php artisan infyom.publish:tables livewire

The above commands will publish the following two files,

sh
config/livewire-tables.php
resources/views/common/livewire-tables/actions.blade.php

Then, we will need to update config/livewire-tables.php and set theme variables to,

sh
'theme' => 'bootstrap-4',

Since Laravel Livewire Tables is dependent on Laravel Livewire, we need to also update our layout file for livewire.

Open you resources/views/layouts/app.blade.php and do the following modification,

sh
...
<head>
   ...
   @livewireStyles
   ...
    @stack('page_css')
</head>

<body>
   ...
   <script src="//unpkg.com/alpinejs" defer></script>
   @stack('third_party_scripts')
   @livewireScripts
   ...
</body>

Available Options

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.

sh
php artisan infyom:scaffold $MODEL_NAME --views=index,create,edit,show

Soft Delete

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

You can configure it from config file. In order to enable it, set,

sh
'options' => [
    'soft_delete' => true,
],

If you want to customize delete_at column then you can specify it via

sh
'timestamps' => [
    'deleted_at' => 'custom_deleted_at',
],

Timestamps

Timestamp generation can be controlled via timestamps option. You can disable it. Or you can specify custom timestamp field names by,

sh
'timestamps' => [

    'enabled' => true,

    'created_at' => 'added_at',

    'updated_at' => 'modified_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.

It's enabled by default. If you don't want to save your schema files then make it false.

sh
'options' => [
    'save_schema_file' => false,
],

Schema folder can be configured in config.

sh
'path' => [
    'schema_files' => resource_path('model_schemas/'),
],

Repository pattern

By default, the generator uses Repository Pattern. If you don't want repository pattern then you can disable it from config.

It's enabled by default, in the configuration file in 'options' => 'repository_pattern' => true. If you don't want to generate repository then make it false.

sh
'options' => [
    'repository_pattern' => false,
],

Generate Factory

The Generator also provides an option to generate Factory class along with all the model fields with Faker integration which can be directory used in Tests.

sh
'options' => [
    'factory' => true,
],

Generate Seeder

The provides an option to generate Seeder class for the occasions where you need to seed some data into database.

sh
'options' => [
    'seeder' => true,
],

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.

Here is the definition and possible options for schema field:

sh
{
    "name": "title",
    "dbType": "string",
    "htmlType": "text",
    "validations": "required",
    "searchable": true
},

You can also define relationship in field as following:

sh
{
    "name": "writer_id",
    "dbType": "integer:unsigned:foreign,writers,id",
    "htmlType": "text",
    "relation": "mt1,Writer,writer_id,id"
}

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:

sh
{
    "type": "relation",
    "relation": "1tm,Comment,post_id"
}

Custom Table Name

You can also specify your own custom table name by,

sh
php artisan infyom:scaffold Post --table=articles

Generate From Table

sh
php artisan infyom:scaffold Post --fromTable --table=posts

Generate from specific connection (database)

When you have more than one connections (databases), for e.g, database1 and database2 and you want to create scaffold, api or api_scaffold from specific connection's table at that time you can use this option.

sh
php artisan infyom:scaffold Post --fromTable --table=posts --connection=remote

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.

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

sh
php artisan infyom:scaffold Post --primary=post_id

Custom Plural Name

If you have a model name where you need to pass it's plural name manually which sometimes makes more sense then you can do this with the following option. Sometimes it makes sense while using it with different languages.

sh
php artisan infyom:scaffold AuthorBook --plural=AuthorBooks

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.

If you want to add multiple prefix than prefix separate by slash . Like, v1/admin then you can use --prefix=v1/admin option.

sh
php artisan infyom:scaffold Post --prefix=admin

Ignore Fields

While generating from table, if you want to skip certain type of fields like GeoPoint, Last Login time etc. which you do not expect user to insert via CRUD form, then you can use this option to specify those ignored fields.

sh
php artisan infyom:scaffold Post --ignoreFields=geo_location,last_login

Force Migration

If you want to run migration at the end of the CRUD generation without the console prompt, the you can use this option.

sh
php artisan infyom:scaffold Post --forceMigrate

API Resource Generator

If you want to use Laravel Eloquent Resources in your API, then you can use this option.

All you have to do is change the value into generator's config file.

sh
'options' => [
    'resources' => true,
],

File Creation / Deletion Events

When you fire the scaffold / api_scaffold or rollback command we are dispatching following events to track file creation and deletion.

  1. File Creating / Created
  2. File Deleting / Deleted

Where File Creating / Created events will be dispatched when scaffold / api_scaffold command fired. following are the related events names that you can use for listening events.

  1. GeneratorFileCreated
  2. GeneratorFileCreating

And File Deleting / Deleted events will be dispatched when rollback command fired. following are the related events names that you can use for listening events.

  1. GeneratorFileDeleting
  2. GeneratorFileDeleted