مرور رنگبندی دستاوردها0:28
This is just a simple explanation with no code.
Adding Skill Level Test0:51
And then red will be for the advanced level achievements. Okay, so with that in mind, let's do this. Let's go to my achievementType test. And we'll add a new one here. It sets a skillLevel. So let's grab this and bring it down. And we'll say, well, by default, maybe we'll make all of them intermediate. So let's do this. It sets a default skillLevel. So if we do not specify one, if I get the, do I want skill, or skillLevel, or just level?
Fetch the skill level for the Achievement type. However, if we come back to our test again, and well, maybe we don't need to add anything else besides that. We have our method on the parent class. If you need to override it, for example, down here, if you said the level would be advanced, and if we give the test another run, of course, it's going to fail, because now we are overriding that. So you do have that ability. So that's good. But now I do want to ensure that we are persisting this in the database.
Testing Database Persistence2:21
So that's good. But now I do want to ensure that we are persisting this in the database. So why don't we go up here and add one for all of the attributes. We could say it persists the achievement data in the database. That's horrible. It persists the achievement attributes in the database. Okay, fine enough. So let's instantiate this. And you'll remember, as part of that, we will ensure that the necessary record exists in the database.
And you'll remember, as part of that, we will ensure that the necessary record exists in the database. So if I were to say achievement and give me the first one, that would be the only one there is. Let's save that. And just to show you, let's dd it and give this a run. And sure enough, we do have exactly one achievement. So let's make sure that those values do line up with what we would expect. Okay, so let's say this assertEquals, and let's see, description would be some fake description.
Okay, so let's say this assertEquals, and let's see, description would be some fake description. Okay. So we'll compare that against the description. Give that a run, and we get green. We also need the name, so that would be fake achievementType. Run that. This should all pass. So we have the name. What else do we have here?
So we have the name. What else do we have here? The name, the description, the icon, and then of course, we need the skill level as well. So the icon is fake achievement type.svg. That's the default, right? Give that a run. That works. And then finally, this is the one that is going to break. We need to check the skill level. And by default, it'll be intermediate.
Updating Migration Schema3:54
We need to check the skillLevel. And by default, it'll be intermediate. All right, so if I give that a run, now it's going to fail. Okay. Let's go to our migration. Create Achievements table. And right down here, we'll add another one for the skillLevel. And let's see. Do we want to make that accept anything? Or we could, of course, do an enum type.
Do we want to make that accept anything? Or we could, of course, do an enum type. And that might be a good way to go. That way, we could say only accept beginner, intermediate, and advanced. And if you make a mistake and you try to pass that, it's going to blow up. Okay. Okay. And now, we will rerun the migration, and it fails. Oh, well, for one, we could add a default here. So I could say default is intermediate.
Oh, well, for one, we could add a default here. So I could say default is intermediate. And if we run that again, yeah, now we get green. But also, we need to ensure on our achievementType right here that we call this method. So we're basically enforcing a default in two different locations, which you may or may not want to do. But it's okay here. Anyways, if we give that a run, it'll work. Or let's go back to our test, scroll down, and why don't we override it here? We'll say return advanced or expert, whatever values we want to do.
Applying Levels to UI5:31
Okay. So now, think about it. Now, we have a way for each achievement to determine what skill level it's associated with. So we set $data to add a custom class, and that's how we set the unique background colors. So if we go and update this section here that's in profile/slash/banner right here, yeah, what we're going to do is dynamically build up something like that. So if we now take a look at these, they would have something like that, is advanced. Then you could say, give me an achievement that is advanced, and that should have a background color of red or something along those lines.
Then you could say, give me an achievement that is advanced, and that should have a background color of red or something along those lines. You get the idea. All right. Let's do this first trial just to show you. Yeah. Some would be red, some would be blue, some would be green. Okay. So if we want to grab this, I'll just say isAchievementLevel.
Rerunning Migrations and Sync6:17
So if we want to grab this, I'll just say achievementLevel. Okay. Let's come back, refresh, and if we take a look, is, oh, it's not showing up. You know why? It's because we need to, on my local end, I need to update the migration. You can do that with a quick php artisan migrate. Roll back, and php artisan migrate. But now, once again, we're not going to see it because I did reset the migration, so I don't have those achievements in the DB anymore. Let's boot up php artisan tinker and forget what we have in the cache.
don't have those achievements in the DB anymore. Let's boot up php artisan tinker and forget what we have in the cache. Then I can run that command to sync all of the user's various achievements. Anyways, if we come back and refresh, there we go. So now, because we haven't overwritten any, we'll get isIntermediate for each one of these achievements. Okay. But yeah, finally, just to be quick, let's do it manually. We'll update that to advanced. All right.
