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
62. Improving solution marking

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
Coming back to something else that we noted earlier on our discussion solution patch controller, if, for example, a user was to pass through a post ID that didn't belong to this discussion, what's actually going to happen is that's going to be set in this column here.
00:16
We really need to know that the post that we're marking as a solution within the discussion row in the discussions table actually belongs to that discussion. So basically, only posts within that discussion could be marked as the solution for that discussion. So let's go ahead and figure this out.
00:35
And I put topic here earlier, but of course, I meant discussion. So there are a couple of ways that you can achieve this. You can create out an if statement. So you could say, for example, take the discussion, go into posts,
00:49
and you could say something like contains and the post that we are looking for. So we'd have to define this somewhere else up here. Let's just make this really messy for now. Reference the post down here.
01:04
And then, of course, go ahead and check if it contains that post. Now, if it doesn't contain that post, then we could do something like abort, whatever you wanted to do. So let's just abort with a status 200 for now,
01:15
just to test this out, because this is not the solution that we're going to roll with. So when I click to mark this as the best solution, sure enough, it still works. We do get an issue here at the moment, because, of course, we are passing a null value down. So we'd need to take that into account as well.
01:32
So I think that for the purpose of this, this is not the best solution, because there are additional conditions around this. And it just doesn't really make sense. So what we're going to do is we're going to get rid of all of this.
01:41
And instead, we are going to, from here, access the discussion. We're going to go into posts. And we're just going to directly find. So kind of like what we were doing before, when we just said post find,
01:56
but this time, we're finding a post within the discussion post relationship. So that way, based on that relationship, we always know it has to exist within the discussion post. So we're going to go ahead and find. And let's just remind ourselves where this came from.
02:12
I think we called this. We just head over to our post. Let's find the solution section. And what do we call this?
02:20
Post ID. OK, so find request post ID. OK, so let's head over now and try this out. When I unmark this, it still works.
02:30
When I mark it, it still works. But now, if we were to pass through a post that didn't exist within that discussion, it just wouldn't work, because it wouldn't be able to find it. The worst case scenario here is it's just going to clear out the solution
02:42
if we try and do that, because we know we get a null back from here. Now, another thing that we could do, we don't necessarily need to do this, because we have already implemented this solution, is we could add some validation here just to make sure that this post actually exists.
02:57
So if you wanted to do that, if you were to roll with another solution, you're going to want to make sure that the post ID exists in general. So if it doesn't exist at all, then there's no point in even trying. So here we could go ahead and just say that this is required.
03:11
So that's pretty important. We could say rule exists. And we want to make sure that that exists within the post table under the ID column. So let's go ahead and pull in rule here from Illuminate Validation.
03:26
Now, this isn't going to work when we unmark it, because technically it does not exist then. So what we can actually do is set this rule to nullable as well. And if we come over, hit this.
03:38
That is, yeah, that's going to need to replace the required rule. So let's hit unmark. That works. Looks like, yeah, just the post model doesn't exist in there.
03:49
And let's try that again. There we go. So everything is working. We've got validation in place, which isn't completely necessary,
03:55
because we now know that whatever ID we pass in, whether it exists or not, is always being looked at within the discussion post. So there we go. Another fix just to improve the way that this works.
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!