Konstruktory w klasach rozszerzających Eloquent
Właśnie otworzyłem nową stronę i chciałem skorzystać z Eloquent. W procesie rozsiewania mojej bazy danych zauważyłem, że dodam puste wiersze dodane, jeśli włączyłem dowolny konstruktor do modelu, który rozwinie się elokwentnie. Na przykład uruchomienie tego siewnika:
<?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'
)
);
}
}
Z tym jako moja klasa Team:
<?php
class Team extends Eloquent {
protected $table = 'tm_team';
protected $primaryKey = 'team_id';
public function Team(){
// null
}
}
Daje to:
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
Samo usunięcie konstruktora pozwala siewnikowi pracować zgodnie z oczekiwaniami. Co właściwie robię źle z konstruktorem?