如何在mysql查询laravel中插入where条件?

如何在mysql查询laravel中插入where条件?,laravel,Laravel,我尝试用代码插入 $info = DB::table('role_user')->where('user_id', '=',$current) ->where('role_id', '=',$id)->get(); 插入错误 $response = $info->insert(array('active' => 1)); 您不能将同一角色\u用户插入两次,但可以更新它 $response = DB::table('role_user')->where('u

我尝试用代码插入

$info = DB::table('role_user')->where('user_id', '=',$current)
->where('role_id', '=',$id)->get();
插入错误

$response = $info->insert(array('active' => 1));

您不能将同一
角色\u用户插入两次,但可以
更新它

$response = DB::table('role_user')->where('user_id', '=',$current)
->where('role_id', '=',$id)->update(array('active' => 1));

您应该运行更新查询:

$response = DB::table('role_user')
->where('user_id', $current)
->where('role_id', $id)
->update(array('active' => 1));

不清楚您是在选择还是插入记录?插入到角色用户表?告诉我这和我的答案有什么不同?实际上,是相同的代码。即使您的描述也比我好,但我试图让代码变得可读性和简洁。