Defining Models
Within the models
section of a draft file you may define multiple models. Each model is defined with a name followed by a list of columns. Columns are key: value
pairs where key
is the column name and value
defines its attributes.
Expanding on the example above, this draft file defines multiple models:
models:
Post:
title: string:400
content: longtext
published_at: nullable timestamp
Comment:
content: longtext
published_at: nullable timestamp
# additional models...
From this definition, Blueprint creates two models: Post
and Comment
, respectively. You may continue to define additional models.
Blueprint recommends defining the model name in its StudlyCase, singular form to follow Laravel's model naming conventions. For example, use Post
instead of post
, Posts
, or posts
.
For each of the model columns, the key
will be used as the exact column name. The attributes are a space separated string of data types and modifiers.
For example, using the Post
definition above, Blueprint would generate the following migration code:
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title', 400);
$table->longText('content');
$table->timestamp('published_at')->nullable();
$table->timestamps();
});