我正在使用以下代码更新A记录的两个字段:
$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 = [];
最佳答案
试试这样的方法:
CompanyPlan::where('company_id', $companyId)->first()
->update(['plan_id' => $planId, 'next_plan_id' => $planId]);