Run Time 7:25Free
To begin, we'll need to setup our initial database structure. This way, we can store community links, and associate them with any number of channels/categories. While we're here, we'll also set up a quick registration system. Luckily, because we have Laravel, that only takes a moment.
Run Time 8:38
Let's figure out how to render a list of community links on the page. This will require us to prepare some dummy data using database factories.
Run Time 8:40
Our next step is to add a form to the page, which allows a logged-in user to contribute any link to the list.
Run Time 5:14
We're not quite done with the contribution form just yet. Let's write some validation code, and display the errors in the form.
Run Time 13:49
Up until now, we've used placeholders for anything related to the assigned channel for each community link. Let's fix that in this lesson. We'll need to populate the channels table, display them within a
select element, and then update our validation code to ensure that we only allow valid channel ids.
Run Time 9:26
We initially decided that all submitted links should be approved; however, that's not reflected anywhere on the site just yet. Let's update our code, so that it only fetches approved links. Next, we'll update the users table to add a new
trusted column. This will indicate whether or not we should automatically approve submissions.
Run Time 7:40
In the last video, we realized that some form of flash messaging will be needed. Let's tackle that in this lesson. While Laravel offer session flashing out of the box, we'll pull in a small little package to expedite the whole process. This will also make preparing modals much simpler.
Run Time 18:28
How should we handle the situation where a person attempts to submit a link that has been previously shared by somebody else? Rather than allowing or preventing duplicate links entirely, let's instead touch the timestamps of the old submission. That way, it will jump back to the top of the page. In the process of implementing this, we'll discuss and review exceptions and form objects.
Run Time 10:35
We'll tackle two things in this lesson. First, we'll clean our views up a bit and render the proper pagination links. Next, we'll figure out how to sort all of the links, according to their category. This will allow for easy filtering.
Run Time 10:34
We're making good progress, but we haven't yet begun working on the voting functionality. This is what allows users to vote on articles that they like. It'll take a couple lessons to knock out, but let's get started with the basic structure.
Run Time 18:44
We're still working on the voting functionality, so let's get back into it in this lesson. We'll set up the necessary endpoints, create a form, and then refactor our existing logic just a bit.
Run Time 15:02
Let's update our query to allow for sorting the results by the votes relationship count. As you'll see, we'll need to expand our main Eloquent query quite a bit. We'll even extract it to its own dedicated query object.
Run Time 4:59
We now have the ability to sort according to popularity, so the only remaining step is to offer the user tabs to switch between sorting options. While we're here, we'll also refactor our initial database query a bit.
View the source code for this series on GitHub.