Sergey
Sergey

Reputation: 17

Unique query for one record

I need to turn off the "where" for one entry that I know of. I don’t understand how to do this. To understand the general problem: I need a collection with all the records + a unique one for which the "where" has not been applied. They should be displayed in the usual manner. Perhaps there is a solution to add this entry to the collection after querying sort the new collection?

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

Upvotes: 0

Views: 34

Answers (1)

Anthony Aslangul
Anthony Aslangul

Reputation: 3847

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

Is it what you are looking for? It will get all records where published_at is not null or where the id is $your_id_here.

Upvotes: 1

Related Questions