请求更新B. laravel 5.4
如何更新多行
我落在肿块以下
我的控制器
我落在肿块以下
[
"3",
"4",
"5"
]
我的控制器
$answers= $request->get/'option'/; //answers array
foreach /$answers as $answer/
{
Answer::where/'question_id', 1/->update/
['customer_id' => 1,
'answer' => $answer]/;
}
没有找到相关结果
已邀请:
3 个回复
莫问
赞同来自:
如果你使用 Eloquent ORM, 然后使用以下请求
App\Answers::where/'question_id', 2/->update/['customer_id' => 1,'answer'=>2]/;
君笑尘
赞同来自:
DB::table/'answers'/->where/'id',2/->update/['customer_id' => 1, 'answer' => 2]/;
最好使用模型 Eloquent, 例如,
Answer::where/'id',2/->update/['customer_id' => 1, 'answer' => 2]/;
如果您未将此列添加到属性中
模型,然后你可以用它来更新 after find like,
我希望你明白。
小明明
赞同来自:
:
Answer::where/'question_id', 2/->update/['customer_id' => 1, 'answer' => 2]/;
方法 update 期望一系列的一对列和值表示必须更新的列
不要忘记添加
,
在阵列中
https://laravel.com/docs/5.4/e ... nment
:
protected $fillable = ['customer_id', 'answer'];