我有以下插入:
$id = \DB::table('log')
->insert(array(
"account_id" => $this->get("account_id"),
"type" => "Edit info",
"done" => "0"
));
当 log 表中没有这样的先前条目时,我该如何调整它才能仅执行?
account_id: 1// 类型:编辑信息// 完成:0
我需要避免重复条目(如果用户已经请求编辑他/她的信息并且管理员尚未完成,则不会有相同的条目)。
最佳答案
您可以使用updateOrInsert
方法。
$id = \DB::table('log')->updateOrInsert(array(
"account_id" => $this->get("account_id"),
"type" => "Edit info",
"done" => "0"
));
关于php - 当/如果 X 时执行 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56328524/