如何在Laravel中更新具有不同ID的多行 [英] How to update multiple row with different ID in Laravel
本文介绍了如何在Laravel中更新具有不同ID的多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我问的最后一个问题.
This is from the last question that I asked..
我有一个会员表
Schema::create('role_memberships', function (Blueprint $table) {
$table->increments('id');
$table->integer('role_id');
$table->string('MembershipName');
$table->text('MembershipValue');
$table->timestamps();
});
我有两行数据具有相同的role_id,我想更新两行 这是我的控制器
I have two rows data with same role_id and I want to update two rows This is my controller
$updateArray = [['MembershipValue' => $request->PostAdMaxImage],
['MembershipValue' => $request->PostAdExpiredDay]];
DB::table('role_memberships')->where('role_id', $id)-
>whereIn('role_id', $role->pluck('id'))->update($updateArray);
当我尝试更新时,我得到了一个错误数组,用于字符串转换.
when I tried to update, I got an error array to string conversion..
推荐答案
我认为这只是我可以使用的方式.
I think this is only the way that I can used..
DB::table('role_memberships')->where('role_id', $id)->where('MembershipName','PostAdMaxImage')->update(['MembershipValue' => $request->PostAdMaxImage]);
DB::table('role_memberships')->where('role_id', $id)->where('MembershipName','PostAdExpiredDay')->update(['MembershipValue' => $request->PostAdExpiredDay]);
如果你们有最好的方法或最短的方法,请让我知道..谢谢;)
If you guys has the best way or the shortest way, please let me know.. thankyou ;)
这篇关于如何在Laravel中更新具有不同ID的多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文