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');
?
感謝年底,這個需要一些測試,但並聽起來不可思議。我會檢查那個拉請求 – brazorf
是啊...設置它,看看你是否仍然得到錯誤...然後你會知道 – lagbox