Appearance
Getting Started
Generator Commands
Generator provides various commands to generate scaffold & APIs.
sh
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,
sh
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
- Validations
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
name of the field (snake_case recommended). for e.g.,
- title
- user_id
- body
- status
db_type
database type of the field. e.g.
- string -
$table->string('field_name')
- string,25 -
$table->string('field_name', 25)
- text -
$table->text('field_name')
- For Enum, enum,Sun,Mon,Tue -
$table->enum('field_name', ['Sun', 'Mon', 'Tue'])
- integer,false,true -
$table->integer('field_name',false,true)
- string:unique -
$table->string('field_name')->unique()
- For foreign keys
- foreignId:constrained - $table->foreignId('field_name')->constrained()
- integer:unsigned:foreign,table_name,id -
$table->foreign('field_name')->references('id')->on('table_name')
- integer:unsigned:foreign,table_name,id,cascade -
$table->foreign('field_name')->references('id')->on('table_name')->onUpdate('cascade')->onDelete('cascade')
html_type
html type of field for forms. e.g.
- text
- textarea
- password
Here is the full guide for html 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
- iv - to skip field from being displayed in all views
so here are some examples, how field inputs can be passed together
sh
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
- numeric
You can pass the exact same string as Laravel doc suggests. for e.g. required|unique:posts|max:255
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.