2014-04-28 92 views
1
class User extends Eloquent { 

    protected $table = 'my_users'; 

    // The 'my_users' table does *not* provide this column. 
    protected $computedValue; 

    public function doSomething() { 
     // Anyway, for some reason, i need the property to exist in the model. 
     $this->computedValue = 'foo'; 
    } 
} 

當我做User::save(),就會觸發一個錯誤,因爲雄辯試圖insert into my_users (computedValue) values('foo')Laravel 4,如何防止Eloquent模型處理某些屬性?

其實,我解封屬性之前我觸發保存。是否有其他方式(除了聽儲蓄事件來解除事物之外),就像

protected $discard = array('computedValue', 'anyOtherFieldNotToMap'); 

回答

相關問題