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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners