https://dev.to/dcblog https://res.cloudinary.com/practicaldev/image/fetch/s--LfcyWuZm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dcblog.dev/images/posts/adding-pinned-posts-with-laravel.png Let's say you have a blog and have posts ordered by their published date.

Pinned posts should be displayed before any other posts regardless of their published date.

Adding a second-order clause: ->orderBy('is_pinned', 'desc')->orderBy('published_at', 'desc'); This time ordered by a is_pinned column then order by the published_at column.

Adding a migration to add a column called is_pinned to a posts table php artisan make:migration add_pinned_field_to_posts #migration Migration boolean('is_pinned')->default(false); }); }
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners