我使用以下代碼更新了記錄的兩個領域:Laravel更新方法不按預期工作
$companyPlan = CompanyPlan::whereCompanyId($companyId)->first();
$companyPlan->update(['plan_id' => $planId, 'next_plan_id' => $planId])
它所做的是,它更新plan_id
領域,但不next_plan_id
。
plan_id
和next_plan_id
都位於模型的$ fillable數組中。
這真的是一個奇怪的行爲,但我無法知道爲什麼會是這樣的原因。
protected $fillable = ['plan_id', 'next_plan_id'];
protected $hidden = [];
由於您正在使用的只有一種模式:你嘗試明確設置的參數,然後保存();? – Kjell
不應該在哪裏':: where('company_id',$ companyId)' – Jonathan
@Kjell你的意思是更新()方法不適用於一個模型?如果這就是你說的話,那麼爲什麼它只更新plan_id而不是next_plna_id,無論我改變它們的位置或順序。 – MKJ