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
It is really important how to use generator.
Generator supports three methods of input:
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 you 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. There is some format in which we have to specify field inputs
name db_type html_type options
Here is what this means,
name-name of the field (snake_case recommended)
db_type-database type. 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,
- integer:unsigned:foreign,tablename,id - `$table->foreign('fieldname')->references('id')->on('table_name')`
- integer:unsigned:foreign,tablename,id,cascade -`$table->foreign('fieldname')->references('id')->on('table_name')->onUpdate('cascade')->onDelete('cascade')`
- string -
html_type-html field type for forms. e.g.
Here is the full guide for 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.
- 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.