In this episode, we tackle a common yet tricky UI component: dynamic breadcrumbs in Laravel. Breadcrumbs can quickly get messy, especially as your routes get more advanced with things like model binding. So, we're going to walk step-by-step through creating your own workflow for generating dynamic breadcrumbs based on the current URL segments, and, importantly, pulling model-based titles instead of just displaying slugs.
First, you'll see how to break down the segments of the URL to generate breadcrumbs, and why simply using title case on slugs isn't good enough—especially when slugs change or when you want more readable breadcrumb links. We illustrate the limitations of hacky solutions and then move forward to a more robust and maintainable approach.
The heart of the episode is refactoring all this logic into a dedicated Breadcrumbs
class, complemented by a Segment
class, and hooking it up via a custom Request macro. We cover how to:
title
vs name
)I also point out a popular Laravel package if you want a completely manual breadcrumbs setup, but if your breadcrumbs should mirror your URL structure (which is typically the case), our method will work great.
By the end, you’ll have a clean, reusable way to add dynamic breadcrumbs to your Laravel apps that are aware of models, not just URLs. And as always, lots of code snippets and practical inline explanations so you can see everything in action.