-
Notifications
You must be signed in to change notification settings - Fork 2
7.3 makeModel
Lucas F. Lu edited this page Jan 31, 2020
·
3 revisions
This command helps building a model file by taking an argument as the model name and generates a migration if needed.
-
Option "datafields" or flag "-D" defines the model fields. It is reaquired and the format for its value is:
fieldname:fieldname:dataType(option)[modifier,...]
Example of creating a model that has a table called "person", primary key by "idx" with a nullable, string typed field called "name" and defauts to "John", a set typed field called "gender" with values between "male" and "female" is given below.
Example: php artisan bp:makeMigration person -D="idx:bigIncrements[primary=true];name:string(100)[nullable]<John>;gender:set(male,female)" -K="idx"
- To generate a migration file at the end use flag "-M"
- Option "path" or flag "-P" specifies the path to store the model file. Default is "/app/Model"
- Option "key" or flag "-K" specifies the primary key of the model
- Use flag "-W" to use wizard when creating a model. When wizard is used, no model name is needed.
increments
bigIncrements
mediumIncrements
smallIncrements
tinyIncrements
integer
mediumInteger
bigInteger
smallInteger
tinyInteger
unsignedBigInteger
unsignedInteger
unsignedMediumInteger
unsignedSmallInteger
unsignedTinyInteger
binary
boolean
char:option (Size). example => name:char(100)
date
dateTime
dateTimeTz
decimal:option (total digits,decimal digits). example => number:decimal(8,2)
double:option (total digits,decimal digits). example => number:double(8,2)
enum:option (value list seperated by comma ","). example => enums:enum(a,b,c,1,2,3)
float:option (total digits,decimal digits). example => number:float(8,2)
geometry
geometryCollection
ipAddress
json
jsonb
lineString
longText
macAddress
mediumText
morphs
uuidMorphs
multiLineString
multiPoint
multiPolygon
nullableMorphs
nullableUuidMorphs
point
polygon
rememberToken
set:option (value list seperated by comma ","). example => sets:set(a,b,c,1,2,3)
string:option (Size). example => name:string(100)
text
time
timeTz
timestamp
timestampTz
timestamps
timestampsTz
unsignedDecimal:option (total digits,decimal digits). example => number:unsignedDecimal(8,2)
uuid
year
You can seperate each modifiers with comma ","
autoIncrement: Integer type auto-increment
nullable: Allows (by default) NULL values to be inserted into the column
unsigned: Set INTEGER columns as UNSIGNED (MySQL)
useCurrent: Set TIMESTAMP columns to use CURRENT_TIMESTAMP as default value
primary: Set as Primary Key
editable: Make field available for mass assignables
Feedback is much appreciated! I can be reached at [email protected]