2017-02-13 8 views
0

私は、インサートのmysqlクエリlaravelのwhere条件を挿入するには?

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

エラーコードを挿入しようと

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

レコードを選択または挿入しようとしているのは不明ですか? –

+0

role_userテーブルに挿入 –

答えて

0

あなたが実行する必要がありますupdateすることができます更新クエリ:

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

これは私の回答とどのように違うのですか? – KuKeC

+0

実際には、同じコード。あなたが私よりも優れているとは言えますが、私はコードを読みやすく、きれいにしました。 –

1

あなたは二度同じrole_userを挿入することはできませんが、それは

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