In this episode, we're tackling one of the core features of our app: letting users upload and store videos. We start by wiring up the backend so that when a video is submitted (with a title and description), it's properly sent, stored, and handled securely. We make sure the video file gets saved in the public filesystem, give each video a UUID so filenames aren't easily guessable, and get everything ready for later encoding.
We walk through creating the necessary controller and database migration, add all the needed fields to our videos
table (like title, description, file path, UUID, thumbnail path, and user association), and run the migration. Then, we set up the user relationship so we know who owns which videos.
A big chunk of the episode is spent ensuring that when a video gets uploaded, it actually gets moved to the right spot in the file system, and our database records what's where. To handle UUIDs automatically, we set up a model observer that attaches a UUID to every new video. We test the workflow end-to-end and confirm everything is saving and redirecting as it should.
To make sure junk doesn't get into our database, we add proper validation with a Form Request, checking for video type (supporting mp4, webm, mkv for best browser compatibility), required fields, and sane limits. We also tweak the frontend so when forms submit, the scroll position is preserved, making for a smoother UX.
By the end of this video, uploading a video file with all the relevant info is fully working. Next up: encoding the video so it plays everywhere, and grabbing a still image to preview our uploads on the index screen.