This episode is for members only

Sign up to access "Build a Forum with Inertia and Laravel" right now.

Get started
Already a member? Sign in to continue
Playing
44. Deleting discussions

Episodes

0%
Your progress
  • Total: 6h 54m
  • Played: 0m
  • Remaining: 6h 54m
Join or sign in to track your progress
01. Introduction and demo
6m 59s
0%
02. Getting set up
10m 36s
0%
03. Modifying registration for usernames
7m 15s
0%
04. Figuring out the forum layout
5m 57s
0%
05. Creating and listing topics
9m 15s
0%
06. Basic discussion listing
13m 33s
0%
07. Pinning discussions
4m 1s
0%
08. Tackling pagination in Inertia
8m 23s
0%
09. Customising pagination text in Laravel
52s
0%
10. Showing a discussion
6m 4s
0%
11. Setting up discussion posts
5m 53s
0%
12. Listing through discussion posts
5m 28s
0%
13. Adding more data to posts
8m 24s
0%
14. Adding pagination to posts
1m 35s
0%
15. Adding a post preview to discussions
4m 52s
0%
16. Adding the last reply to discussions
5m 54s
0%
17. Outputting discussion participants
8m 4s
0%
18. Limiting participants in the UI
5m 56s
0%
19. Ordering discussions by last post
4m 30s
0%
20. Handling deleted users
2m 31s
0%
21. Counting replies
8m 13s
0%
22. Building our first filter
8m 31s
0%
23. Highlighting current filters, and merging with pagination
5m 37s
0%
24. Adding auth specific filters
6m 40s
0%
25. Adding the topic filter
8m 18s
0%
26. Scaffolding the new discussion form
13m 29s
0%
27. Toggling the create discussion form
9m 2s
0%
28. Keeping form state
4m 59s
0%
29. Storing a new discussion
11m 29s
0%
30. Discussion validation and authorization
5m 1s
0%
31. Generating markdown for posts
8m 37s
0%
32. Toggling the markdown preview
7m 43s
0%
33. Fetching and displaying markdown
8m 6s
0%
34. Adding a markdown shortcut toolbar
5m 53s
0%
35. Dealing with SVG icons
7m 46s
0%
36. Creating the reply form
7m 48s
0%
37. Basic Inertia permission checking
6m 26s
0%
38. Creating replies to discussions
5m 37s
0%
39. Jumping to posts
11m 40s
0%
40. Automatically scrolling to posts
6m 18s
0%
41. Toggling post editing
7m 32s
0%
42. Editing posts
3m 36s
0%
43. Deleting posts
4m 21s
0%
44. Deleting discussions
6m 7s
0%
45. Setting up for best answers
7m 29s
0%
46. Toggling the best discussion answer
12m 14s
0%
47. Solved and unsolved filters
2m 23s
0%
48. Indexing discussions for search
8m 6s
0%
49. Searching discussions
12m 35s
0%
50. Debouncing search
2m 47s
0%
51. Adding mentionable functionality to forms
6m 32s
0%
52. Indexing users for mentioning
9m 9s
0%
53. Hooking up users for mentions
10m 10s
0%
54. Detecting and storing mentioned users
9m 54s
0%
55. Adding the mentioned filter
2m 26s
0%
56. Adding mentions to the markdown toolbar
1m 1s
0%
57. Adding mentions to the reply form
7m 21s
0%
58. Fixing up some unauthenticated state
1m 1s
0%
59. Fixing up post scrolling
1m 48s
0%
60. Reviewing SSR (Server-side rendering)
8m 20s
0%
61. Preventing parent posts from being deleted
2m 31s
0%
62. Improving solution marking
4m 9s
0%

Transcript

00:00
We're pretty much going to repeat what we just did in the last episode,
00:03
but this time we're going to delete entire discussions. And once again, our database should handle this by removing all posts that are part of them discussions. And before we do that, I'm just going to create a
00:14
another discussion out here called Delete Me, just so we've got something to play around with. And let's choose a topic here, start this discussion, and we're going to delete this entire discussion.
00:26
So once again, we're going to need authorization. That's a really, really important part of this here. So we're going to head over to the discussion policy, and we're going to go ahead and just duplicate one of these down
00:36
and say, delete or destroy. And we will get a user in here. We will get a discussion in here. And once again, the condition here is the same. We just need to be able to, or we just need to actually own this discussion.
00:49
So let's say that the user ID equals the discussion's user ID. OK, so now that we've done that, we can head over to the discussion resource and we can add this in here. So really, we're just repeating what we've already done here.
01:04
OK, so now that we've done that, we can head over to the show page where we are outputting the title of the discussion just here, and we can go ahead and show this button next to it. So let's, well, that's the topic title.
01:19
There's the discussion title. So let's go ahead and add this just into here. In fact, we'll do this outside of the H1. And we're going to create an unordered list
01:27
because we might have some other options in here later. And let's put an if statement on this. And we know that this is whether the discussion user can delete. And in here, let's go ahead and create out a button.
01:43
And we'll say delete here. And let's just see if that shows for now. And it does. If we head over to a discussion that we didn't start,
01:50
so I think this one maybe, of course, we don't see the button. So as long as we own that discussion, we're all good. And we're now showing that button now. So let's go ahead and just add some classes on this.
02:00
So we'll pretty much do what we did with the buttons within the post and set the text to small. That should just be about it. Great.
02:10
OK, so what are we going to do when we click on this? Well, pretty much what we did within our post. We just want to call some sort of method to go ahead and handle this directly with the NERSH's router.
02:19
So let's call this delete discussion. And let's come to our script section. And let's go down just to the bottom here. Create this out real quick.
02:29
And we're just going to post through. Of course, we don't have anywhere to go through to yet. So let's go ahead and create out our route and our controller. So again, just following the same pattern,
02:39
we're going to go ahead and make out a discussion destroy controller. And let's head over to our web routes and create our route for this. So let's copy this one here. We'll say delete, deleting that discussion in here.
02:55
And discussion destroy controller. And we'll say discussion and destroy. Let's make sure we're keeping the same names here. That's fine.
03:07
OK, so over to the discussion destroy controller. Once again, we're going to go ahead and create out a form request immediately for this. So let's go ahead and make one out now.
03:16
Make request. And that is, of course, going to be discussion destroy request. Let's add that directly into here. And we should be good.
03:30
Let's add that into the request. And let's say discussion in here. And there we go. So let's make sure we just pull the namespace in for that.
03:39
And again, we're just going to do the same thing. Discussion, delete, and then return back. And that's pretty much it. Now, we aren't actually going to return back.
03:47
So we do need to change this around. Because, of course, we can't return back to the discussion that has been deleted. So in this case, let's go ahead and say redirect route. And let's see what we called our home page.
04:03
Probably just home. Yeah, probably best to just jump straight over to the home page. OK, so over in the discussion destroy request, let's go ahead and authorize this. So auth user can delete.
04:17
And again, this discussion. So exactly like what we did with our posts. And we should be good. So let's just go and hook this up on the client side and see if this works.
04:29
So I don't think we have our router pulled in here. No, we don't. So let's go and pull this in first of all. And then if we head down, let's go ahead and say router delete.
04:43
Again, give the root name in here. Discussions destroy. Passing through the discussion. And then again, we don't necessarily need to worry about preserve scroll here,
04:57
because when we delete this over in here, we're going to be redirected back to the forum anyway. So let's actually skip that option entirely, because it's completely unnecessary. OK, so let's go ahead and try this out. Just bringing up my console just in case.
05:12
And let's hit delete here. Now, of course, that looks like it did absolutely nothing. So let's have a look here. I don't even think.
05:21
Did we hook this up to our button? So I put the if you probably notice this. So V on click. There we go.
05:29
OK, now we didn't add a wrapper around this to confirm. So let's do that really quickly. So if window confirm. Are you sure?
05:39
And if we are sure, then we go ahead and delete it. So let's try this out. OK, I'm going to cancel that off and hit OK. OK, so discussions destroy is not in the root list.
05:49
So obviously something's gone wrong there. Discussions and where are we? Discussions dot destroy. Great.
05:58
OK, so that should fix that up. Great. We're redirected back to the home page. And of course, you can see that discussion has now been deleted.
62 episodes6 hrs 54 mins

Overview

Ready to build a forum with Inertia and Laravel?

Why a forum? A forum touches a whole load of concepts that you'll use throughout your development career – particularly on the client-side, where we'll be doing most of the heavy lifting.

So, let's build a clean, modern forum with features like markdown support, code highlighting, advanced filtering, user mentions, full-text search, the ability to mark best answers, and more.

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

Episode discussion

No comments, yet. Be the first!