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
07. Pinning 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 now going to take a quick look at pinning discussions, because that's going to form how we're going to order all of the discussions on our forum index. Eventually, these are going to be ordered by the last post.
00:11
So as soon as someone adds a reply to a topic or a post to a topic, that will be pushed to the top of this list. We're not going to do that now, but we'll work on pinned, so we have a good start.
00:23
So the first thing is just to add in a pinned boolean to our discussions table. So add pinned at to discussions table. And we're using a timestamp here, so we know when it's pinned. It can still work out if it's pinned, if it's been filled.
00:46
It's always a good idea to have a reference to the date in here as well. So add pinned at, we can spell that to discussions table. OK, so this is going to be a timestamp. And of course, that's going to be pinned at.
01:02
And we're going to make this nullable, because of course, not every discussion is going to be pinned. And let's go ahead and just say drop column on pinned on the down migration. OK, we'll go ahead and migrate this.
01:14
And there we are. OK, so over on our discussion, let's implement a really simple method in here to detect whether this is pinned or not. So public function is pinned, I guess.
01:27
And we'll say if this is not null, and this pinned at. Because remember, that is going to be a date as well. So we're not going to implement any casting on this, just because this is going to be set via an admin panel at some point.
01:42
If you choose to do that, you can cast this. So you get a carbon instance back as well. So let's head over to our discussion resource. And let's add whether this is pinned.
01:54
So we'll say is pinned, or you can output the date that this has been pinned. And we'll just say this is pinned. And we should be good. So now over on the discussion component,
02:05
we can just output whether it's been pinned or not. And we're just going to do this in a really, really basic way. And all we're going to do is create out a template here. And just say if discussion is pinned,
02:21
then we're just going to output pinned in here. That's it. So none of these are pinned at the moment. But let's go ahead and pin one of the discussions that we have in here.
02:31
So let's choose this need help with Laravel, because remember, that was created first. So technically, when we add in our ordering, that should be shown last.
02:43
But that should be bumped to the top with pinned eventually. Now the ordering is a little bit messed up here. So we're going to tackle that next. Over on the forum index controller,
02:54
the first thing I'm going to do is set this to latest. So the latest topic goes to the top. But we're going to remove that later, because the topics with the latest post are eventually going to go to the top.
03:06
So we're going to add latest in there for now. But let's add a note to remove that when implemented ordering by last post. That kind of makes sense. So now we just need a way to order this by the pinned.
03:20
And we're going to do that over in the discussion. We'll just create our scope in here. So let's create a scope called ordered by pinned. Into this, we get a query builder,
03:34
which we can use to just continue to add to our query. So we're going to order by pinned at in ascending order. So let's go ahead and add this scope in here. Order by pinned.
03:50
And we should see pinned jump to the top. Everything else will be ordered by the latest that it was created, or the latest discussions will be at the top. But pinned will always stay at the top.
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!

Comments

No comments, yet. Be the first to leave a comment.