Seeding Database Setup0:00
Before we can start to implementing our controllers, we need some data to work with. So let's seed our database. And when it comes to our CER, we don't need a User because everything kind of hinges upon the profile. Well, doesn't kind of, it does hinge upon the profile. And we need our Post, we need our Like model and then we need the Follow model and that is gonna be it. So in the run method, we can get rid of this default code given to us.
Creating Profiles and Posts0:31
So in the run method, we can get rid of this default code given to us and instead we are going to create some profiles. So let's say that we will have what, 20 profiles. So we will create those and then from there we just need to create posts for those users or not those users, those profiles. Then we need to set up the likes and the follows and things like that.
Then we need to set up the likes and the follows and things like that. So we're gonna have several loops to do that. And the first one is going to iterate over our profiles so that we can create the posts for those profiles. And let's say that each profile is going to have five posts and we will create them so that the profile ID is the profile ID that we are currently iterating over. And yeah, that is going to give us our posts. Now when it comes to setting up likes
Generating Random Follows1:26
And yeah, that is going to give us our posts. Now when it comes to setting up likes and things like that, uh, I think we are going to need all of our posts. So let's go ahead and let's just grab all of them. But the next thing we need to do is set up the followers so that we can follow other profiles. So once again, we are going to iterate over our profiles and we kind of want this to be a little random. So let's do this.
and we kind of want this to be a little random. So let's do this. We'll have something called toFollow, which is going to contain all of the profiles that this particular Profile that we are working with is going to follow. But you know, when it comes time to fetching those random profiles, we want to do so except where the profile is the profile that we are currently working with because a profile cannot follow itself. But then we want a random set.
because a profile cannot follow itself. But then we want a random set. And you know, let's say that we'll have uh, anywhere from three to seven and then from there we just need to iterate over everything inside of twoFollowAs and let's call it a target so that we have a follower that is going to create a follow for the given target and that will set up a random set of follows.
Adding Likes to Posts2:39
for the given target and that will set up a random set of follows for the profiles. So I think that's gonna work well there so that then we can implement the likes, which means that once again, we need to iterate over our profiles as the profile. And then from here we kind of need to do the same thing. We need to get a certain amount of posts that we want to like, but, and you know, a profile can like its own posts,
to like, but, and you know, a Profile can like its own posts, but let's say that we are going to fetch any number of posts that were not written by this particular Profile. So we want where the profile_id is not the profile_id and let's grab a random set of those. So let's say from 10 to 20. And then from there we need to iterate over to like as we'll just call it post so that we can create a like
Creating Reposts and Replies3:31
And then from there we need to iterate over two like as we'll just call it post so that we can create a like for the given profile and the given post. So that gives us, let's see our profiles, our posts, our follows, and our likes. But then I want to set up, you know, things like replies and reposts. So as far as our reposts, let's start kind of like what we did with the likes. So let's just copy that loop so
what we did with the likes. So let's just copy that loop so that we're gonna iterate over our profiles once again. And we want to repost where our posts are not written by the profile that we are working with. But let's change this to be from a random of two to five, so that then we will iterate over our reposts so that we can post repost and it was profile and then the post. And you know, it really doesn't matter if it's a
and it was profile and then the post. And you know, it really doesn't matter if it's a quote post or not. All we really need are some reposts. I say that, but I guess let's be thorough here and let's have some quote reposts. So we're gonna do this, we'll get a random between 0 and 1 so that it will either return null or we'll have some text like great post and okay, so we will have some reposts.
or we'll have some text like great post and okay, so we will have some reposts that will be a normal repost or a quote repost. So we're gonna be good to go there. So that now we just need some replies and let's do something like this. We, we've done some random stuff, so let's just continue that randomness and we'll add, you know, 20 to 30 replies. So our condition is as long as our counter is less than 20
and we'll add, you know, 20 to 30 replies. So our condition is as long as our counter is less than 20 or 30 or anywhere in between there, really, then we want to increment that so that then we can grab a parent post, which we'll get from our posts and let's just get a random post. But we do need to know who is going to reply to this. So we need a reply and you know, it really doesn't matter who that reply is,
So we need a reply and you know, it really doesn't matter who that reply is, but ideally we don't want, you know, the author of whatever, you know, parent post that we have here. So we want a reply where the profileId is not the id of the parent post profileId. But anywhere from that we'll just get a random reply so that we can use our factory to reply to the parent post.
that we can use our factory to reply to the parent Post. And the profileId will be the reply id and that should get us. So we have our profiles, we have our posts for the profiles, then uh, we have our follows, we have our likes, we have our reposts, and then our replies. I don't see any errors. So assuming that I've typed everything correctly,
Running Seeder and Verifying6:42
I don't see any errors. So assuming that I've typed everything correctly, then we should be able to say php artisan, DB, C, and hopefully everything works. We don't get any errors. So it looks like that worked. Of course, there's nothing like actually going to the database and just sniffing around. So we have 20 profiles. That's good. We should have a lot of posts because we created posts for each profile.
We should have a lot of Posts because we created Posts for each profile. Then there are reposts and then there are replies. So as long as we have some reposts of IDs that are not null and we have some parent IDs that are not null, then everything looks good there. Let's take a look at the likes table and sure enough, we have some likes. Let's look at the follows. And we have some data there. So we have our data all set to go so we can start
Let's look at the follows. And we have some data there. So we have our data all set to go so we can start to implementing our ProfileController in the next episode.
