In this episode, we tackle adding tags to our blog posts in a really straightforward way. Instead of setting up a complicated relational database or separate tags table, we just put tags directly into each post’s metadata file as a YAML array. This keeps things simple, but still lets us do some neat stuff, like filtering posts by tag later on.
We walk through setting up the YAML front matter to include a tags
array, sticking with lowercase for easier handling down the line. Then we look at how Laravel parses this data for us, which means our tags are readily available as an array—no extra conversion needed. That makes it super easy to iterate over them.
Next, we update our post meta component to display each tag, wrapping them in styled anchor tags in a list, using a bit of utility-first CSS styling (with some tweaks to layout and spacing). We also show how to prettify the tag names (like turning laravel
into Laravel
) for display, while keeping them lowercase for work behind the scenes—like when we eventually want to show all posts tagged with something specific.
By the end of the episode, you’ll have tags showing up nicely on your blog posts, styled and ready for use. The groundwork’s in place to filter posts by clicking on a tag, which we’ll set up in an upcoming episode!