Table names
When creating a Model, you won't need to name the model table. Larawiz automatically creates the table using the plural name of the model.
yaml
models:
Post:
title: string
excerpt: string
body: longText
1
2
3
4
5
2
3
4
5
php
class Podcast extends Model
{
// ...
}
1
2
3
4
2
3
4
php
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('excerpt');
$table->longText('body');
$table->timestamps();
});
1
2
3
4
5
6
7
2
3
4
5
6
7
You can override the automatic table name with the table
key and the new name of the table. Larawiz will make the changes on both the Model and the migration.
For example, we can set the Post
model to use the blog_posts
table:
yaml
models:
Post:
title: string
excerpt: string
body: longText
timestamps: ~
table: blog_posts
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
php
class Podcast extends Model
{
protected $table = 'blog_posts';
}
1
2
3
4
2
3
4
php
Schema::create('blog_posts', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('excerpt');
$table->longText('body');
$table->timestamps();
});
1
2
3
4
5
6
7
2
3
4
5
6
7
It's your table name
If you issue the table name equally to the plural, Larawiz will still add the $table
property.
Table names on Pivot Models
Larawiz uses Laravel conventions to name the table of a Pivot Model.
yaml
models:
User:
# ...
Podcast:
# ...
Subscription:
# ...
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
php
Schema::create('podcast_user', function (Blueprint $table) {
// ...
})
1
2
3
2
3
You can override the table name using the table
key with a Custom Model.
yaml
models:
# ...
Subscription:
columns:
# ...
table: subscriptions
1
2
3
4
5
6
7
2
3
4
5
6
7
php
Schema::create('subscriptions', function (Blueprint $table) {
// ...
})
1
2
3
2
3