Skip to main content
Version: 3.0.x

Available Commands

Available Commands

The option in between the square brackets [] must be replaced with a variable of your choice.

  • Main commands
    • php artisan create:layout [application-name]
    • php artisan create:scaffold [model-name]
    • php artisan create:controller [model-name]
    • php artisan create:model [model-name]
    • php artisan create:form-request [model-name]
    • php artisan create:routes [model-name]
    • php artisan create:migration [model-name]
    • php artisan create:language [model-name]
    • php artisan create:mapped-resources
  • Views commands
    • php artisan create:views [model-name]
    • php artisan create:index-view [model-name]
    • php artisan create:create-view [model-name]
    • php artisan create:edit-view [model-name]
    • php artisan create:show-view [model-name]
    • php artisan create:form-view [model-name]
  • Resource's files commands
    • php artisan resource-file:from-database [model-name]
    • php artisan resource-file:create [model-name]
    • php artisan resource-file:append [model-name]
    • php artisan resource-file:reduce [model-name]
    • php artisan resource-file:delete [model-name]
  • Migration commands
    • php artisan migrate-all
    • php artisan migrate:rollback-all
    • php artisan migrate:reset-all
    • php artisan migrate:refresh-all
    • php artisan migrate:status-all
  • API generation commands
    • php artisan create:api-scaffold
    • php artisan create:api-controller
    • php artisan create:api-resource
  • API documentation generation commands
    • php artisan api-docs:scaffold
    • php artisan api-docs:create-controller
    • php artisan api-docs:create-view

Important Naming Convention

Laravel-Code-Generator strive to generate highly readable, and error free code. In order to keep your code readable, it is important to follow a good naming convention when choosing names for your models, fields, tables, relations and so on. Here is a list of recommendation that we believe is important to keep your code clean and highly readable.

  1. Since each model represents a single object/row in a list/database, naming the model should be written in singular-form while using Studly Case. For example, Post and PostCategory...
  2. Since a database is a collection of model's object, table naming should always be plural and written in lowercase while using Snake Case. For example, users, post_categories...
  3. Primary keys should be named id in the table.
  4. Since the foreign key represents a foreign/other table, the name should always end with _id. For example, post_id, user_id, post_category_id...
  5. Field naming should always be in a singular-form and written in lowercase while using Snake Case. For example, title, first_name, description...

Examples

The following example assumes that we are trying to create a CRUD called AssetCategory with the fields listed below.

  • id
  • name
  • description
  • is_active
info

A layout is required for the default views! You can use command to create a layout using the command-line. Of course you can use your own layout. You'll only need to include CSS bootstrap framework in your layout for the default templates to work properly. Additionally, you can chose to design your own templates using a different or no css framework.

Basic example

php artisan resource-file:create AssetCategory --fields=id,name,description,is_active

The above command will create resource-file names /resources/laravel-code-generator/asset_categories.json

php artisan create:scaffold AssetCategory

The above command will create a model app/Models/AssetCategory, a controller app/Http/Controllers/AssetCategoriesController, all views, the routes, and migration file!

Basic example using translations for English and Arabic

php artisan resource-file:create AssetCategory --fields=id,name,description,is_active --translation-for=en,ar

The above command will create resource-file names /resources/laravel-code-generator/asset_categories.json

php artisan create:scaffold AssetCategory

The above command will create a model app/Models/AssetCategory, a controller app/Http/Controllers/AssetCategoriesController, all views, the routes, and migration file!

Basic example with form-request

php artisan resource-file:create AssetCategory --fields=id,name,description,is_active

The above command will create resource-file names /resources/laravel-code-generator/asset_categories.json

php artisan create:scaffold AssetCategory --with-form-request

The above command will create a model app/Models/AssetCategory, a controller app/Http/Controllers/AssetCategoriesController, all views, the routes, and migration file!

Basic example with soft-delete and migration

php artisan resource-file:create AssetCategory --fields=id,name,description,is_active

The above command will create resource-file names `/resources/laravel-code-generator/asset_categories.json``

php artisan create:scaffold AssetCategory --with-soft-delete --with-migration

The above command will create a model app/Models/AssetCategory, a controller app/Http/Controllers/AssetCategoriesController, all views, the routes, and migration file!

Creating resources from existing database.

php artisan create:scaffold AssetCategory --table-exists

The above command will create resource-file names /resources/laravel-code-generator/asset_categories.json

Then it will create a model app/Models/AssetCategory, a controller app/Http/Controllers/AssetCategoriesController, all views and the routes!

You may also create a resource-file from existing database separately using php artisan resource-file:form-database AssetCategory

Creating resources from existing database with translation for English and Arabic

php artisan create:scaffold AssetCategory --table-exists --translation-for=en,ar

The above command will create resource-file names `/resources/laravel-code-generator/asset_categories.json``

Then it will create a model app/Models/AssetCategory, a controller app/Http/Controllers/AssetCategoriesController, all views and the routes!

You may also create a resource-file from existing database separately using

php artisan resource-file:form-database AssetCategory --translation-for=en,ar

Creating resources from existing database with translation for English and Arabic in two step for better control over the fields!

php artisan resource-file:form-database AssetCategory --translation-for=en,ar
php artisan create:scaffold AssetCategory

The above command will create resource-file names /resources/laravel-code-generator/asset_categories.json

Then it will create a model app/Models/AssetCategory, a controller app/Http/Controllers/AssetCategoriesController, all views and the routes!

How To

::: Info All examples below assumes that you already created a resource-file (i.e resources/codegenerator-fields/posts.json. This file can be created using the following command php artisan resource-file:create Post --fields=id,title,details,is_active) :::

How to create "views-layout"?

To create a new layout for your application.
php artisan create:layout [application-name]

The argument [application-name] should be replaced with the name of the application you are creating. For example:

php artisan create:layout "My New Laravel App"
OptionDescriptionDefault
--layout-filenameThe name of the layout file to be used.app (i.e, creates app.blade.php)
--layout-directoryThe directory to create the layout under.layouts
--template-nameThis option allows you to use a different template at run time. When this option is left out, the default template is used.

Note: the default template can be set from the config file (i.e config/laravel-code-generator.php) by setting the template key to a different value.
layouts
--forceThis option will override the layout if one already exists.

How to create resources (complete CRUD)?

Create multiple resources at the same time. It can be invoked every time the resource-file is modified to recreate the resources all over again.
php artisan create:scaffold [model-name]

The argument [model-name] should be replaced with the name of the model you are creating. For example:

php artisan create:scaffold Post
OptionDescriptionDefault
--resource-fileThe name of the file to import resource from. This option allows you to have all resources such as fields, indexes and relations in one JSON file, and then import it from the command line. This is a powerful feature which makes it easy to configure the fields, then reuse the same fields in multiple command now or in the future. More documentation on how to manage resource-file can be found in the "Managing fields using JSON file" section.the plural-form of the model name. If the model name is AssetCategory, the name will then be asset_categories.json
--controller-nameThe name of the controller to create. If the provided value does not end with the word "Controller" it will be appended.The controller's name will be generated using the plural-form of the giving model's name. In the above example, the controller will be called "PostsController".
--controller-extendsSpecify which class should the controller extends. Note: the default value is can be set change by modifying config file (i.e config/laravel-code-generator.php).default-controller which means use the settings from the configurations by default Http\Controllers\Controller
--with-authAdds the auth:api to the controller which prevents any un-authenticated users to access the resources.
--routes-prefixPrefix of the route group.default-form which uses the plural-form of the model name. However, this is something can be changed from the configuration file plural_names_for key.
--models-per-pageHow many models to show per page on the index view.25
--with-form-requestInstead of placing the field's validation rules directly in the controller class, this option will extract the rules into a separate form-request class. The form-request class allows you to do more complex validation, cleans up your controller, and increases your code reusability. By default, the method authorize() is set to return false for your application's security. This method must be modified to return a true value for the store and update requests to be allowed. Otherwise, the request will be Forbidden. When using --with-auth option, the authorize() method return Auth::check() which should always return true at this point.
--table-nameThe database's table name. If this option is left out, it is assumed that the table name is the plural-form of the model-name. In the above example, the table name will be "posts". If the model name is AssetCategory, the table name will be "asset_categories".
--table-existsThis option allows you to generate resources from existing database table. When this option is used, the database's name is assumes to be the plural-form of the provided "model-name". Of course, the table name can be set to a different value by passing the --table-name option.

When using this option, the command php artisan resource-file:from-database is called behind the scenes to generate a a resource-file first. The name of the generated resource-file will be named the plural-form of the model, unless an explicit name is provided using the --resource-file`` option. This file will allow you to change the default behavior and recreate the view to fit your needs. <br /><br /> This option is currently available only for MySql database only. It will not work if used with a different driver. <br /><br /> Note: To create multiple-language translation from existing database, use the --translation-for option`.
--translation-forA comma separated languages. When creating resources from existing database using the --table-exists options, --translation-for allows you to create multi-language labels. You still have to provide translation for the corresponding language but it will get everything setup for you.

If this option is left out, no translation key's will be generated.

For example, passing --translation-for=en,ar,fr will create label under the following languages en, ar and fr.

This option will only work when using --table-exists option otherwise it is ignored.
--language-filenameThe languages file name to put the labels "if any" in. When no value is provided, the file name will be the plural-form of the provided model name.

Note: if the file already exists, and the same key field name exists in the file, no message will be added.

This option will only work when using --table-exists option.
--primary-keyThe field's name of the primary key. The default value can be overridden by setting the is-auto-increment or the is-primary flag to true in the fields setup.id
--with-soft-deleteEnables the soft-delete feature that Eloquent provides.
--without-timestampsPrevent Eloquent from maintaining both created_at and the updated_at properties.
--with-migrationThis option will create a migration for your resource.

Behind the scenes, this option invokes the create:migration command to create the required migration.
--migration-class-nameThe name of the migration class. If this option is not set, a name will be generated based on the model name.
--connection-nameEloquent uses the configured default database connection. Providing a value here will tell Eloquent to connect using the provided connection.
--engine-nameA specific engine name for the database's table can be provided here.
--controller-directoryThe directory where the controller should be created under. For example, if the word "Frontend" was provided, the controller will be created in App/Http/Controllers/Frontend directory.

The default path where the controller will be created can be set from the config file config/laravel-code-generator.php.
--model-directoryA directory where the model will be created under. The default path where the model will be created can be set from the config file config/laravel-code-generator.php.
--views-directoryThe name of the directory to create the views under. If this option is left out, the views will be created in /resources/views
--form-request-directoryThe directory where the form-request should be created under.

For example, if the word "Frontend" was provided, the form-request will be created in App/Http/Requests/Frontend directory. The default path where the form-request will be created can be set from the config file config/laravel-code-generator.php
--fieldsDescribed here
--template-nameDescribed above
--forceThis option will override the layout if one already exists.

How to create multiple resources at once?

Create multiple resources at the same time
   php artisan create:mapped-resources

When using resource-file:create, resource-file:from-database or resource-file:delete the resources_map.json file is updated behind the scenes. This options create multiple resources for all the resources found in the resources/laravel-code-generator/sources/resources_map.json at the same time. The resources can be invoked every time any of the resource-file is modified to recreate the resources all over again.

OptionDescription
--controller-extendsDescribed above
--with-authDescribed above
--models-per-pageDescribed above
--with-form-requestDescribed above
--without-form-requestAllow you to create all the resources excluding the form-request if one is used. Note: when creating a controller with a form-request the form-request is injected into the action methods. Thus, in order to create the form-request based controller, you would have to use --with-form-request and --with-form-request so the controller know you are using form-request but avoid overriding existing form-request.
--form-request-directoryDescribed above
--table-existsDescribed above
--translation-forDescribed above
--primary-keyDescribed above
--with-soft-deleteDescribed above
--without-timestampsDescribed above
--with-migrationDescribed above
--connection-nameDescribed above
--engine-nameDescribed above
--controller-directoryDescribed above
--model-directoryDescribed above
--views-directoryDescribed above
--template-nameDescribed above
--mapping-filenameThis option allows you to pass the name of the mapping-directory file. When this option is left out, the default `resources_map.json`` file will be used.
--forceThis option will override the layout if one already exists.

How to create a controller?

Create a controller for your resource.
php artisan create:controller [model-name]

The argument [model-name] should be replaced with the name of the model you are creating. For example:

php artisan create:controller Posts
OptionDescription
--controller-nameDescribed above
--controller-directoryDescribed above
--resource-fileDescribed above
--routes-prefixDescribed above
--models-per-pageDescribed above
--language-filenameDescribed above
--with-authDescribed above
--with-form-requestDescribed above
--without-form-requestDescribed above
--form-request-directoryDescribed above
--model-directoryDescribed above
--views-directoryDescribed above
--without-languagesAllow you to create all the resources excluding the language file if one is needed. Note: the language file will only be created if the resource file contains translations.
--without-modelAllow you to create all the resources excluding the model.
--without-viewsAllow you to create all the resources excluding the views.
--template-nameDescribed above
--forceThis option will override any file that already exist.

How to create a model?

Create a model.
php artisan create:model [model-name]

The argument [model-name] should be replaced with the name of the model you are creating. For example:

php artisan create:model Post
OptionDescriptionDefault
--resource-fileDescribed above
--routes-prefixDescribed above
--table-nameDescribed above
--primary-keyDescribed above
--with-soft-deleteDescribed above
--without-timestampsDescribed above
--model-directoryDescribed above
--template-nameDescribed above
--forceThis option will override any file that already exist.

How to create routes?

Create routes for your CRUD operations.
php artisan create:routes [model-name]

The argument [model-name] should be replaced with the name of the model you are creating. For example:

php artisan create:routes Post
OptionDescriptionDefault
--controller-nameDescribed above
--routes-prefixDescribed above
--without-route-clauseCreate the routes without where clause for the id. It may be used when the primary key is not an integer
--for-apiCreate API based routes.
--for-versionprovide the version of the api to create the routes for.
--table-nameDescribed above
--template-nameDescribed above

How to create all standard CRUD views (i.e. Create, Read, Update and Delete)?

When creating views using the create:views, create:create-view or create:update-view an additional view called "form-view" is created. The "form-view" contains the form fields to prevent code duplication.

Create routes for views for CRUD operations.
php artisan create:views [model-name]

The argument [model-name] should be replaced with the name of the model you are creating. For example:

php artisan create:views Post
OptionDescriptionDefault
--resource-fileDescribed above
--routes-prefixDescribed above
--layout-nameDefault value layouts.app. A different layout could be used to generate the views. This can easily be done by providing a different layout name. For example, if the physical path to a different layout was /resources/views/layouts/template/newlayout.blade.php`` then its name would be layouts.template.newlayout`.
--only-viewsThe only views to be created. A comma separated string with the name of the views to create. By default, create the create,edit,index,show, and form views.
--views-directoryDescribed above
--template-nameDescribed above
--forceThis option will override any file that already exist.

How to create a view for the Create Operation?

Create a create-view.
php artisan create:create-view [model-name]

The argument [model-name] should be replaced with the name of the model you are creating. For example:

php artisan create:create-view Post
OptionDescriptionDefault
--resource-fileDescribed above
--routes-prefixDescribed above
--layout-nameDescribed above
--views-directoryDescribed above
--template-nameDescribed above
--forceThis option will override any file that already exist.

How to create a view for the Edit Operation?

Create an edit-view.
php artisan create:edit-view [model-name]

The argument [model-name] should be replaced with the name of the model you are creating. For example:

php artisan create:edit-view Post
OptionDescriptionDefault
--resource-fileDescribed above
--routes-prefixDescribed above
--layout-nameDescribed above
--views-directoryDescribed above
--template-nameDescribed above
--forceThis option will override any file that already exist.

How to create a view for the List Operation?

Create an index-view.
php artisan create:index-view [model-name]

The argument [model-name] should be replaced with the name of the model you are creating. For example:

php artisan create:index-view Post
OptionDescriptionDefault
--resource-fileDescribed above
--routes-prefixDescribed above
--layout-nameDescribed above
--views-directoryDescribed above
--template-nameDescribed above
--forceThis option will override any file that already exist.

How to create a view for the Display Operation?

Create an show-view.
php artisan create:show-view [model-name]

The argument [model-name] should be replaced with the name of the model you are creating. For example:

php artisan create:show-view Post
OptionDescriptionDefault
--resource-fileDescribed above
--routes-prefixDescribed above
--layout-nameDescribed above
--views-directoryDescribed above
--template-nameDescribed above
--forceThis option will override any file that already exist.

How to create a form-view?

Create an form-view.
php artisan create:form-view [model-name]

The argument [model-name] should be replaced with the name of the model you are creating. For example:

php artisan create:form-view Post
OptionDescriptionDefault
--resource-fileDescribed above
--routes-prefixDescribed above
--layout-nameDescribed above
--views-directoryDescribed above
--template-nameDescribed above
--forceThis option will override any file that already exist.

How to create a database migration?

Create a database migration.
php artisan create:migration [model-name]

The argument [model-name] should be replaced with the name of the model you are creating. For example:

php artisan create:migration Post
OptionDescription
--table-nameDescribed above
--resource-fileDescribed above
--migration-class-nameDescribed above
--with-soft-deleteDescribed above
--without-timestampsDescribed above
--connection-nameDescribed above
--engine-nameDescribed above
--template-nameDescribed above
--forceThis option will override the file if it already exists.

How to create form-request?

Create a form-request for request validation.
php artisan create:form-request [model-name]

The argument [model-name] should be replaced with the name of the model you are creating. For example:

php artisan create:form-request Post
OptionDescription
--class-nameDescribed above
--resource-fileDescribed above
--with-authDescribed above
--routes-prefixDescribed above
--form-request-directoryDescribed above
--template-nameDescribed above
--forceThis option will override any file that already exist.

How to create a language file?

Create a new language file.
php artisan create:language [model-name]

The argument [model-name] should be replaced with the name of the model you are creating. For example:

php artisan create:language Post
OptionDescription
--language-filenameDescribed above
--resource-fileDescribed above
--template-nameDescribed above
--forceThis option will override any file that already exist.