방금 새 웹 사이트를 시작했으며 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'
)
);
}
}
을 : 간단하게 생성자를 제거
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
가 모두 함께 같이 일할 수있는 시더 수 있습니다 :
<?php
class Team extends Eloquent {
protected $table = 'tm_team';
protected $primaryKey = 'team_id';
public function Team(){
// null
}
}
하면이냅니다 예상했다. 정확히 내가 생성자에 대해 잘못된 것은 무엇입니까?
public function __construct(array $attributes = array())
{
if (! isset(static::$booted[get_class($this)]))
{
static::boot();
static::$booted[get_class($this)] = true;
}
$this->fill($attributes);
}
boot
메서드가 호출되고 booted
속성이 설정됩니다
Eloquent는 자신 만의 생성자이기 때문에 일하는 것이 웅변적 인 모든 동작을 설정 해제했습니다. – crynobone