Columns
Define a column with a name, and the value as the method to call from Blueprint
class instance. Additional arguments for the method can be defined after the colon, and separated by comma.
models:
Post:
claps: integer:true,true nullable
2
3
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->integer('claps', true, true)->nullable();
$table->timestamps();
});
2
3
4
5
While the above syntax will work for Quick Models, you can have total control on the model itself using Custom Models. For the latter, put your columns and relations inside the columns
key.
models:
Post:
columns:
claps: integer:true,true nullable
2
3
4
Schema::create('posts', function (Blueprint $table) {
$table->integer('claps', true, true)->nullable();
});
2
3
I'll use my own method
If you have a package adding custom columns types, like $table->custom('foo')
or $table->foo()
, no problem, you can typefoo: custom
or foo: ~
, respectively.
Since there is no method checking, you should be careful of typos, as cool_at: timetsamp
will become $table->timetsamp('cool_at')
.
Columns with no values
Column keys with null values, for both Quick Models and Custom Models, will transform into method names with no arguments. This is used for timestamps, soft-deletes and other short-hands from the Blueprint.
models:
Posts:
columns:
id: ~
uuid: ~
softDeletes: ~
timestampsTz: ~
rememberToken: ~
myCustomMethod: ~
2
3
4
5
6
7
8
9
Schema::create('model_name', function (Blueprint $table) {
$table->id();
$table->uuid();
$table->softDeletes();
$table->timestampsTz();
$table->rememberToken();
$table->myCustomMethod();
});
2
3
4
5
6
7
8
Prefer the wavy thing
To issue a null value, use ~
. Some YAML parsers run in circles when a value is empty.