Advanced

Unlocking Badges Workshop

Together, in this series we'll add an "Unlockable Badge" feature to the Laracasts website. Perhaps when a user reaches a certain XP threshold, they unlock a badge. Or when they reach 500 "Best Answer" slots, they earn yet another badge. You get the idea.

Let's research and implement this feature using TDD from scratch.

Start Series

Share this series on:

  • 01

    Episode 1 Run Time 9:23

    Begin With an Example Free

    Like so many other things in life, starting a new feature is the hardest part. We're creating something out of nothing. It's not an easy task to define how that "something" should appear. But we'll try. Let's begin with one example of how the system should behave, using TDD.

  • 02

    Episode 2 Run Time 14:06

    Event Fakery

    Let's drop down a level and write a test to ensure that, when experience is awarded to a user, an announcement (or event) is made to the rest of our application. Later, we'll listen for this announcement and grant any necessary achievement badges to the user.

  • 03

    Episode 3 Run Time 6:01

    Use TDD to Construct Migrations and Attributes

    It sounds like we'll need an Achievement Eloquent model, as well as its associated database table. Let's use TDD to construct both.

  • 04

    Episode 4 Run Time 8:24

    A User Can Be Awarded Achievements

    In this episode, we'll construct the relationship between a user and their respective achievements. As you'll see, this is a prime use-case for a generic pivot table.

  • 05

    Episode 5 Run Time 11:54

    What If We Didn't Use a Database?

    Leading up to this episode, I've been doing some thinking. Yes, we can store achievement badges within the database, but where do we put the logic that determines if the given user should be granted that badge? This led me to considering a different path we might consider. In this episode, let's tinker around with that idea. If we like it, we'll keep it. If we don't, we'll revert!

  • 06

    Episode 6 Run Time 4:16

    Nah

    In the previous episode, we tinkered with the idea of not using a database at all for determining and fetching a user's acquired achievement badges. Let's talk about that refactor - including the pros and cons to such an approach - before ultimately reverting in favor of a better solution for our needs.

  • 07

    Episode 7 Run Time 21:45

    Syncing User Achievements With Collections

    Now that we've reverted the previous lesson's work, we can move on to a clean approach. In this lesson, we'll build the necessary system to register and sync achievements with any given user, based on newly awarded experience.

  • 08

    Episode 8 Run Time 8:22

    Two Ways to Organize a Project New

    In this episode, we'll discuss two equally valid ways to organize all of the achievement-related files, including service providers, events, listeners, etc.

*Series still in development. Check back often for updates.