Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JScheele200's avatar

Pin items to the top of query builder result

Hi!

I want to query a list of restaurants, ordered by date of creation. Restaurants with specific attributes, stored in a JSON column, must be always pinned to the top of the list, regardless of creation date. The list must be paginated.

This is an example of a restaurant data row:

name (String): Burger King
created_at (Timestamp): 2020-02-12 12:04:33
extras (JSON): ['family_friendly', 'clean']

How do i query a list of restaurants where restaurants having the extra: 'family_friendly' are always pinned to the top of the list?

 Restaurant::orderBy('created_at', 'desc')
            ->where('published', $published)
	    -> (?)
	    ->paginate(30)

Thank you!

0 likes
1 reply

Please or to participate in this conversation.