Laravel-5无法在create方法中传递变量

时间:2015-05-18 16:37:59

标签: php laravel-5

我是Laravel的新手。我正在尝试这似乎不起作用

$apartment = new Apartment;
$apartment->update($apartment_input);//$apartment_input is an array

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

很难说你的目标是什么,但看起来你可能想要这个

$apartment = Apartment::create($apartment_input);

$apartment = new Apartment;
$apartment->property = value;
...
$apartment->save();

$apartment = new Apartment($apartment_input);
$apartment->save();

update()不起作用的原因是因为尚未保存行并且尚未分配PK值(如果您使用自动增量或序列)。