モデルを取得して一度にその属性をすべてクリアすると、すべての属性がnull
になるのですか?モデルをフェッチして属性をクリアする
これには方法がありますか?例えば
:
public $protected_schema = ['id', 'created_at', 'updated_at'];
public function clearAttributes()
{
foreach (Schema::getColumnListing($this->getTable()) as $name) {
if (!in_array($name, $this->protected_schema)) {
$this->{$name} = null;
}
}
}
MEH:
$model = Model::findOrFail(1);
$model->clearAttributes();