laravel - 一条记录的唯一查询
问题描述
我需要关闭我知道的一个条目的“位置”。我不明白该怎么做。要了解一般问题:我需要一个包含所有记录的集合 + 一个未应用“位置”的唯一记录。它们应该以通常的方式显示。也许有一种解决方案可以在查询排序新集合后将此条目添加到集合中?
$reviews = Review::query()
->orderBy("id", 'desc')
->whereNotNull('published_at')
//But don't apply whereNotNull ('published_at') to a record with id = ...
->get()
解决方案
$reviews = Review::query()
->orderBy("id", 'desc')
->whereNotNull('published_at')
->orWhere('id', $your_id_here)
->get()
是你要找的吗?它将获取所有记录 where published_at
is notnull
或 where the id
is $your_id_here
。
推荐阅读
- excel - 没有计算的数据透视表
- arm - ARM 程序集 - 无效的立即操作数值
- php - Laravel 验证规则在尝试更新相同的记录而不进行更改时失败
- android - 如何从 fire-base 检索数据到新活动中单击 RecyclerView
- android-studio - 改造插入到房间存储库,但只插入一行
- database - 试图给sqlite数据库中的列唯一约束
- python - 如何将对象转换为字符串 pandas python
- go - 遇到错误 - 在 golang 中实现词法分析器时,所有 go 例程都处于休眠状态
- plot - 如何绘制任何误差与涉及实数求和的问题的精确解之间的关系
- linux - 我如何编写一个 egrep 命令来查找所有大写或小写字母中至少有 5 个连续元音 (aeiou) 的条目?