تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Plan Repost and Follow0:00

We have most of the functionality done. We do, of course, need to do some important things such as reposting posts, liking posts, and following profiles. So let's get those things done. I'm gonna start with the route because I like seeing what the URL is going to be because that gives me an idea of how to implement these kinds of things. So when it comes to doing anything with an existing post, I like the idea of having the URL similar to the reply.

Add Repost and Quote Routes0:29

So when it comes to doing anything with an existing Post, I like the idea of having the URL similar to the reply. So that's, we have the profile and then we have the Post. So that's just what I'm going to do, except that this last segment, we will change it to repost. The method name will be repost, and the name of the route will be repost. And then for the other it'll just be quote, and we'll just make the same changes there. And then as far as that functionality is concerned,

Implement Repost and Quote0:56

and we'll just make the same changes there. And then as far as that functionality is concerned, those are the routes there. So let's open up the PostController and let's implement those. Now we're not gonna hook this up to the UI because we don't necessarily have a great way of doing that. So we're just gonna implement the functionality because you know, for the most part, we know it works. We have those tests that we wrote all that time ago.

because you know, for the most part, we know it works. We have those tests that we wrote all that time ago. So really we just need to take the reply method and copy it and paste it a couple of times. The first method is going to be the repost method, but we don't need any content. So we can get rid of that request object. And then all we need to do is call the repost method, passing in the current profile and the post that we want to repost.

passing in the current profile and the Post that we want to repost. And that's it. We will just redirect for the time being. If Jeffrey wants to change that, then you can, I mean, that's what he can do. And then for the quote, it's practically going to be the same thing, except that in this case, we do want that create Post request. And this way we could just reuse that because all we need to do is verify

And this way we could just reuse that because all we need to do is verify that we have content there. And if we do, great, if not, then validation fails. And yeah, so then we just call repost passing in the currentProfile, the post and the content. And that's that. I mean, it's very simple and it's very straightforward. So with those two things done, what do we have next as far

Add Like Route and Handler2:21

I mean, it's very simple and it's very straightforward. So with those two things done, what do we have next as far as a post is concerned, and I guess that would be liking a post. So let's copy one of these routes, because again, I want to keep this same URL structure, except that in this case we'll just call it like, and the method will be like, and the name will be posts like very simple. And this is gonna be even more simple.

and the name will be posts like very simple. And this is gonna be even more simple because all we need to do here is we know the profile, we know the post, and we just need to create that like, and yeah, that's it. So instead of creating a post, we create the like, which that was on the Like model, I believe. Uh, if we create like, yep, we pass in the current profile and the post that we want to like, and in this particular case, I, I,

and the Post that we want to like, and in this particular case, I, I, we don't need to redirect anything. I don't think. So let's do this. We will return response()->json(), and we will compact(). Like that way, you know, the new like that was created would be sent back to the client and that's gonna be fine. Now, I know that we need to, you know, un repost something. How do we call that? deleteRepost. I guess.

Now, I know that we need to, you know, unrepost something. How do we call that? deleteRepost. I guess. I know that we need to do that. We need to remove a, like we need to, you know, delete a Post or a reply if that's what we wanted to do. And we will definitely implement that. But I think we'll save that for the next episode because I don't wanna do too much in one thing. But really the last thing that I want to do is follow a profile, in which case, you know, we still need

Add Follow Route and Method4:06

But really the last thing that I want to do is follow a profile, in which case, you know, we still need to be inside of our auth middleware group, but you know, we, we could just do something like this to where we have, uh, not necessarily a get request, get request would not be good, but we could have the profile, but that's not going to be enough. I think we will also need another segment that says follow. And this will be on our ProfileController,

I think we will also need another segment that says follow. And this will be on our ProfileController, and we'll just have a method called follow for the lack of anything better. Let's give it a name of profiles.follow. And this is kind of gonna be the same thing as a like, because there's not really something that we are going to redirect to. We are just going to create that follow and then we can provide that follow back to the client.

We are just going to create that follow and then we can provide that follow back to the client. So we just need to open up our ProfileController. And one thing that I wanna do is clean all of this up. You know, we created that timeline query. I kind of wanna do the same thing for the methods here. And we do need to come back to the replies so that we also include, you know, all of the, the like information and things like that. So we're not done, there's just some details.

the like information and things like that. So we're not done, there's just some details that we will need to take care of. But details can come later. I'm more concerned with getting the functionality done first and then focusing on the details. So we have that method called follow. We need the profile that we want to follow, and yeah, let's get the current profile. Something else too that we might want

and yeah, let's get the current profile. Something else too that we might want to think about is having a cleaner way of getting this current profile. Because I mean, yes, we can do it here, but I want something a little bit cleaner. But again, details right now let's focus on getting the functionality done so that we want to create a follow. And we will have the follower, which will be the current

to create a follow. And we will have the follower, which will be the current profile because they are going to follow the profile from our URL. And then in this particular case, let's return response()->json(), once again. And we will include the follow there. So that's the functionality that we need. We know that this is going to work because we've tested that.

Wrap Up and Next Steps6:35

We know that this is going to work because we've tested that. Now of course we haven't tested the actual routes, but that's okay. I'm confident. Famous last words that this is going to work. And so now that we have the ability to create these things to like, and repost and follow in the next episode, we're gonna reverse all of that so that we can, unlike, we can delete posts, we can unfollow things like that.

that so that we can, unlike, we can delete Posts, we can unfollow things like that.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟