php - 如何在 laravel 中添加“和”条件?
问题描述
我想添加另一个条件(L_Examen_Objectif::where('libelle', '=', $request->input('libelle') )->exists())
条件如果我得到相同的libelle具有相同的id它应该返回True
(我不想插入具有相同 id 的相同的 libelle。)
这是我的代码:
public function addPost(Request $request, $id)
{
if (L_Examen_Objectif::where('libelle', '=', $request->input('libelle') )->exists()) {
return 'true';
}
else {
$Examen_data = array(
'libelle' => $request->input('libelle'),
'id_examen' => $request->input('id_examen'),
'id_lexamen' => $id,
);
L_Examen_Objectif::insert($Examen_data);
}
}
解决方案
您可以通过多种方式做到这一点。一种解决方案是:
L_Examen_Objectif::where([
['libelle', '=', $request->input('libelle')],
['other_key', '=', $request->input('libelle')],
])
这是这种方式的模式:
$query->where([
['column_1', '=', 'value_1'],
['column_2', '<>', 'value_2'],
[COLUMN, OPERATOR, VALUE],
...
])
您可以在此处找到更多信息:如何使用 Laravel Eloquent 创建多个 Where 子句查询?
推荐阅读
- python - 猪在Python中拉丁化字符串
- macos - 滚动时如何在 NSTableview 中显示滚动指示器,不滚动时隐藏
- nativescript - 如何在 nativescript angular 中从本地 ios 访问 UIScrollview 委托?
- angular - 角度观察者更改不更新 gui
- azure - Azure AKS 中不同命名空间的多个 Azure 应用程序网关
- python - 使用 sqlalchemy 和 ORM 将数据加密到 Postgres 并从 Postgres 解密
- java - 当我在editText上留下“空白”时如何防止关闭模拟器?
- pandas - 根据两个数据框中的条件从数据框中获取多行
- python - 切换 3D 绘图的 x 轴和 y 轴的位置
- c++ - 我需要 Shift 键的 ASCII 键码。我在互联网上找到的所有号码都不起作用