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.
6 episodes 21 mins

Overview

Let’s skip the database and build the ability to like any model in Laravel, using Redis.

Traditionally you’d reach for the database for this kind of thing, but as you load more models and start performing checks within relationships — things begin to slow down.

With a key-value store like Redis, tracking users who have liked comments (or anything) keeps everything ridiculously fast.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!