Category: Laravel, Laravel, MySQL, MySQL

One of the tasks I needed to complete for my Podcast application was showing in the Podcast view the next and previous podcasts from the same show. I mean, we can’t just tell this to the database and expect the engine to just know what we’re trying to do. In other words, there is no query we can do to retrieve what comes next and what comes before a given record, because SQL doesn’t know what are valid “neighbor” records, less about how to order them natively since the last varies from engine to engine.

Instead of forcing our way inside raw SQL calls to the database and complex queries just for the sake of doing everything in one line, we will just issue two queries more: one for the next record, and other for the previous record.

Let’s say, for example, we use UUID and we want to filter Podcasts by their show UUID.
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