I recently needed to listen to events on a pivot table within the Codecourse codebase. When a user resets progress for a course, and all the episodes they've completed are detached, episode progress (stored in Redis) should be removed.
Extracting some functionality to a trait but need to use the static booted method within that trait? Here's how.
Table names don't change often, but it's still nice to reference table names directly from your Eloquent models, so you don't end up with a bunch of hardcoded table names.
If you're merging multiple models into a Laravel collection or just have a collection of data you need to paginate, here's an easy, clean way to do it.
When you fill a database row with any kind of random or generated data, checking for collisions is a great idea.
If you've tried to use `orderBy` on a previously ordered query in Laravel, you'll probably find it doesn't work. There's a great reason for that, which we'll explain at the end of the post.