自动将值分配给$fillable属性(Laravel 4)


Automatically Assign Values To $fillable attribute (Laravel 4)

我正在尝试使用 Laravel 4 将数据从本地主机数据库同步到实时数据库。除了列是动态的表外,一切正常。所以在我的模型中,我做了这样的事情:

<?php
class myModel extends 'Eloquent {
    protected $fillable = [];
    protected $connection = 'live';
    protected $table = "myLiveTable";
    public function __construct()
    {
        $this->setFillable();
    }
    public function setFillable()
    {
        $fields = someSQLHandler::getColumns('myLocalTable');
        $this->fillable = $fields;
    }
} 

为了防止手动输入$fillable字段中的字段,因为这是不可能的!

有没有办法让它自动分配或至少防止批量分配错误,即使我知道这是一种不好的做法?

谢谢!

使用黑名单而不是白名单怎么样:

protected $guarded = array('id', 'random_column');

并完全取下$fillable