我刚创建了一个新网站,我想使用 Eloquent。在为我的数据库播种的过程中,我注意到如果我在扩展 eloquent 的模型上包含任何类型的构造函数,我会添加空行。例如,运行这个播种机:
<?php
class TeamTableSeeder extends Seeder {
public function run()
{
DB::table('tm_team')->delete();
Team::create(array(
'city' => 'Minneapolis',
'state' => 'MN',
'country' => 'USA',
'name' => 'Twins'
)
);
Team::create(array(
'city' => 'Detroit',
'state' => 'MI',
'country' => 'USA',
'name' => 'Tigers'
)
);
}
}
以此作为我的团队课程:
<?php
class Team extends Eloquent {
protected $table = 'tm_team';
protected $primaryKey = 'team_id';
public function Team(){
// null
}
}
产生这个:
team_id | city | state | country | name | created_at | updated_at | deleted_at
1 | | | | | 2013-06-02 00:29:31 | 2013-06-02 00:29:31 | NULL
2 | | | | | 2013-06-02 00:29:31 | 2013-06-02 00:29:31 | NULL
只需将构造函数全部移除,就可以让播种机按预期工作。我对构造函数到底做错了什么?