Playing
01. Introduction and demo

Transcript

00:00
So ignoring the super boring interface here, in this course I'm going to show you
00:03
how to like things in Laravel using Redis. Now there's a really good reason why I would advise staying away from the database for things like likes.
00:13
And that is, if you end up with a huge list of comments, we only have three here, but if there were more, then going into, say, the collection of if that particular user has liked something
00:25
gets really, really slow. It uses a lot of memory, not necessarily too many database queries, but in my experience, you'll end up, when you have hundreds and hundreds
00:34
of comments, with a much slower experience. So let's go ahead and take a look at how this works. Then we'll get stuff set up. We'll dive into Redis in case you are new,
00:45
and then we'll build out what you see here. So like I said, really, really boring interface, but it does the job. OK, so I've got three comments here.
00:53
If we just take a look in the database really quickly, you can see that we have these in here. There's nothing in this database that says anything about whether these have been liked or not.
01:03
So let's go ahead and like this first one. You can see I'm authenticated up here as a fake user. So when I do like this, you can see that next to this, we get a notification saying you liked this.
01:14
That will remain the same, and that just means that we can show the user, maybe with a different colored icon or something like that, whether they have liked something.
01:23
And we can like any of these. It's incredibly fast, and we can also click this button to unlike them as well. So although we have a really boring interface here,
01:31
you can take everything that you've learned from here and integrate it into your own UI. Now, just a little bit of behind the scenes about how this is going to work, we're
01:39
going to start by building all of this functionality up directly on the comment model. Then at the end of the course, we're going to move this over to a likable trait, which
01:49
means that if you want to apply likes to articles, courses, any other models that you have in your Laravel applications, you can very easily just integrate this likable trait into your model, and you're done.
02:01
You can start to use all of this functionality. OK, so now that we've had a look at this, let's go over, set everything up, and start to build out everything you need to like things in Laravel.

Episode summary

In this introduction episode, we'll kick things off by talking about how to add a “like” feature to your Laravel app—and why it's a good idea to use Redis instead of your database for this. If you’ve ever run into performance issues as your comment section grows, you’ll understand why reading which items a user has liked can get sluggish! So, we’re bypassing the DB for speeds' sake.

I’ll walk through a super simple (and admittedly boring!) interface to demo how liking and unliking comments works—instantly, thanks to Redis. You’ll see that nothing in the regular database tells us what’s been liked; it’s all handled elsewhere. We’ll also cover how to show users what they’ve liked (think: colored icons), and the process is fast and smooth.

By the end of the course, not only will we have this working on comments, but we’ll refactor it into a reusable trait. That means you can easily plug it into anything else—like articles or courses—in your app. It’s super flexible.

So, let’s get ready to set everything up and dive into building out this Laravel like system together!

Episode discussion

No comments, yet. Be the first!