Laravel updateOrInsert 在第一个参数中使用 'OR' 或 'AND' 运算符?
Laravel updateOrInsert with 'OR' or 'AND' operator in first arguments?
虽然 Laravel 查询构建器中的 updateOrInsert
可以有多个参数,但默认使用的运算符是什么。
例如在文档中提到:
DB::table('users')
->updateOrInsert(
['email' => 'john@example.com', 'name' => 'John'],
['votes' => '2']
);
这是否意味着电子邮件 &&
名称已被选中,或者这是否意味着电子邮件 ||
名称已被选中?如果需要,我们如何控制它?
如果这是一个愚蠢的问题,或者如果它没有按照正确的词汇措辞,请原谅我,因为我是 Laravel 的新手。我在文档或 API.
中找不到此信息
updateOrInsert() 方法用于在匹配 条件时更新数据库中的现有记录 或在不存在匹配记录时创建.它的 return 类型是 Boolean.
语法:
DB::table('blogs')->updateOrInsert(
[Conditions],
[fields with value]
);
在您的查询中:
DB::table('users')->updateOrInsert(
['email' => 'john@example.com', 'name' => 'John'],
['votes' => '2']
);
它将检查 email == 'john@example.com'
和 name == 'john'
,然后它会更新 votes=2
。
虽然 Laravel 查询构建器中的 updateOrInsert
可以有多个参数,但默认使用的运算符是什么。
例如在文档中提到:
DB::table('users')
->updateOrInsert(
['email' => 'john@example.com', 'name' => 'John'],
['votes' => '2']
);
这是否意味着电子邮件 &&
名称已被选中,或者这是否意味着电子邮件 ||
名称已被选中?如果需要,我们如何控制它?
如果这是一个愚蠢的问题,或者如果它没有按照正确的词汇措辞,请原谅我,因为我是 Laravel 的新手。我在文档或 API.
中找不到此信息updateOrInsert() 方法用于在匹配 条件时更新数据库中的现有记录 或在不存在匹配记录时创建.它的 return 类型是 Boolean.
语法:
DB::table('blogs')->updateOrInsert(
[Conditions],
[fields with value]
);
在您的查询中:
DB::table('users')->updateOrInsert(
['email' => 'john@example.com', 'name' => 'John'],
['votes' => '2']
);
它将检查 email == 'john@example.com'
和 name == 'john'
,然后它会更新 votes=2
。