I just started a new website and I wanted to make use of Eloquent. In the process of seeding my database, I noticed that I would get empty rows added if I had included any kind of constructor on the model that extends eloquent. For example, running this seeder:
<?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'
)
);
}
}
With this as my Team class:
<?php
class Team extends Eloquent {
protected $table = 'tm_team';
protected $primaryKey = 'team_id';
public function Team(){
// null
}
}
Yields this:
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
Simply removing the constructor all together allows the seeder to work as expected. What exactly am I doing wrong with the constructor?