In this episode, we finally tackle posting a comment to our resource! The big thing we start with is authenticating a user — since we don't have real authentication set up yet, we just "fake" it by force-logging in a test user straight from the database. Later on, we'll do proper authentication, but this is enough to move things along.
From there, we walk through building the UI for leaving a new comment: a textarea, some simple styling (including adding Tailwind CSS's forms plugin for consistency), and a submit button. The form doesn't do anything just yet, but now we're ready to wire up the backend.
We discuss how to make the comments system flexible enough to attach comments to any model (not just articles), using morph maps and Laravel's relationship utilities. To keep it secure, we make sure to not expose any sensitive class names, and validate any posted data. In the controller, we retrieve the correct model and make sure it's actually commentable before saving the new comment.
Once comments can be posted, we fix up redirect behavior so after posting you're sent straight back to your comment in the list. It's a bit rough and ready at this stage, but it works for now — we'll refactor and beautify later.
At the end, we celebrate getting multi-model comments working, and tee up the next episode, where we'll dive into writing good tests for all this new functionality.