TABLE OF CONTENT
Generator provides various commands to generate scaffold & APIs.
php artisan infyom:api $MODEL_NAME php artisan infyom:scaffold $MODEL_NAME php artisan infyom:api_scaffold $MODEL_NAME
Generator Inputs From Console
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,
Specify fields for the model (skip id & timestamp fields, we will add it automatically) (Read docs carefully to specify field inputs) Enter "exit" to finish
Here, you have to insert fields for your 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.
Field input format is divided into four parts,
name <space> db_type <space> html_type <space> options
Here is what each part means.
name of the field (snake_case recommended). for e.g.,
database type of the field. e.g.
- string -
- string,25 -
- text -
- For Enum, enum,Sun,Mon,Tue -
$table->enum('field_name', ['Sun', 'Mon', 'Tue'])
- integer,false,true -
- string:unique -
- For foreign keys
- foreignId:constrained - $table->foreignId('field_name')->constrained()
- integer:unsigned:foreign,table_name,id -
- integer:unsigned:foreign,table_name,id,cascade -
html type of field for forms. e.g.
Here is the full guide for html field inputs.
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.
- 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 - iv - to skip field from being displayed in all views
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
In second field you can specify validations for fields from any available validations of laravel.
You can pass the exact same string as Laravel doc suggests. for e.g.
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.