In this episode, we finally make our post editing feature work for real! Up until now, we've just toggled the edit mode, but in this video, we actually wire up the edit form so users can update their posts.
We start by hooking up the edit form submit event to an editPost
function. Then we create a new patch controller and route for updating posts. We handle the validation and authorization (making sure users can only edit their own posts) using a new request class and our existing policy.
Once that's in place, we update the post with the new data, keep the scroll position on edit (so the page doesn't jump around), and reset the editing state after a successful update. We also do a quick little debugging session when things don't work the first time, and fix it so the correct post gets edited.
By the end of the episode, you can update any post you own, and InertiaJS takes care of updating the data in the UI right away. Nice! Now your edit posts feature is fully functional.