首页 > 解决方案 > 一条记录的唯一查询

问题描述

我需要关闭我知道的一个条目的“位置”。我不明白该怎么做。要了解一般问题:我需要一个包含所有记录的集合 + 一个未应用“位置”的唯一记录。它们应该以通常的方式显示。也许有一种解决方案可以在查询排序新集合后将此条目添加到集合中?

     $reviews = Review::query()
            ->orderBy("id", 'desc')
            ->whereNotNull('published_at')
             //But don't apply whereNotNull ('published_at') to a record with id = ...
            ->get()

标签: laravellaravel-8

解决方案


$reviews = Review::query()
            ->orderBy("id", 'desc')
            ->whereNotNull('published_at')
            ->orWhere('id', $your_id_here)
            ->get()

是你要找的吗?它将获取所有记录 where published_atis notnull或 where the idis $your_id_here


推荐阅读