我嘗試用代碼中插入插入的如何在mysql查詢laravel中插入where條件?
$info = DB::table('role_user')->where('user_id', '=',$current)
->where('role_id', '=',$id)->get();
錯誤
$response = $info->insert(array('active' => 1));
我嘗試用代碼中插入插入的如何在mysql查詢laravel中插入where條件?
$info = DB::table('role_user')->where('user_id', '=',$current)
->where('role_id', '=',$id)->get();
錯誤
$response = $info->insert(array('active' => 1));
您應該運行更新查詢:
$response = DB::table('role_user')
->where('user_id', $current)
->where('role_id', $id)
->update(array('active' => 1));
告訴我這與我的回答有什麼不同?實際上,相同的代碼是 – KuKeC
。即使你描述得比我好,但我試圖讓代碼幾乎不可讀和乾淨。 –
不能插入相同的role_user
兩次,但你可以update
它
$response = DB::table('role_user')->where('user_id', '=',$current)
->where('role_id', '=',$id)->update(array('active' => 1));
目前還不清楚您是否嘗試選擇或插入記錄? –
insert to role_user表 –