Hands On: Community Contributions
In this mini-series, we'll, from scratch, allow users to register, submit community articles and tutorials, and then vote on their favorites. While there are a number of moving parts, it should all make perfect sense, once we're done.
Progress
Series Info
- Episodes
- 13
- Run Time
- 2h 19m
- Difficulty
- Intermediate
- Last Updated
- Aug 12, 2016
- Version
- Latest
Series Episodes
- Episodes (13)
Database Structure
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.Display Community Links
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.Contribute a Link: Part 1
Our next step is to add a form to the page, which allows a logged-in user to contribute any link to the list.Contribute a Link: Part 2
We're not quite done with the contribution form just yet. Let's write some validation code, and display the errors in the form.Channels
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 aselectelement, and then update our validation code to ensure that we only allow valid channel ids.Trusted Users and Approved Links
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 newtrustedcolumn. This will indicate whether or not we should automatically approve submissions.Flash Messaging and Modals
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.Form Objects and Touching Timestamps
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.Pagination and Channel Filtering
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.Voting: Part 1
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.Voting: Part 2
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.Sort By Popularity
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.Most Recent or Most Popular
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.
