问题
I'm trying to Sync data from a Localhost database to a Live one using Laravel 4. Everything works fine except for a table where columns' are dynamic. So in my Model I did something like:
<?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;
}
}
in order to prevent typing the fields in $fillable
manually as it is impossible!
Is there any way to make it automatically assigned or at least prevent the Mass Assignment error even if I know it's a bad practice?
Thanks!
回答1:
How about using a black-list instead of a white-list:
protected $guarded = array('id', 'random_column');
And remove the $fillable
completely.
来源:https://stackoverflow.com/questions/27641854/automatically-assign-values-to-fillable-attribute-laravel-4