2017-02-13 62 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

insert to role_user表 –

回答

0

您應該運行更新查詢:

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

告訴我這與我的回答有什麼不同?實際上,相同的代碼是 – KuKeC

+0

。即使你描述得比我好,但我試圖讓代碼幾乎不可讀和乾淨。 –

1

不能插入相同的role_user兩次,但你可以update

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