In this episode, we start building out the foundation for our chat rooms feature. We kick things off by scaffolding a basic Room model, along with a migration to set up the database table. We keep the room model simple for now, just adding a title
and a slug
, which makes it easy to reference specific rooms via URLs.
Next up, we create the routing and controller logic to allow visiting individual rooms in the browser. We leverage route model binding with slugs so each room gets its own unique URL. There's also a quick walkthrough on creating a controller to handle displaying a room, and how to set up endpoints so users can navigate between different rooms.
On the frontend, we set up an Inertia.js page for an individual chat room, initially by copying over the dashboard layout as a starting point. We start customizing it, passing the room data (transformed nicely using an API resource for neat and secure JSON output) to the frontend. There's a helpful tip for removing the default data wrapper from API resource responses to make things more convenient on the frontend side.
Finally, we lay out the room's main interface with two main sections: one for online users and another for chat messages. We make use of CSS grid to organize these into a nice, spaced layout. The result is a basic but solid structure to build more features on top of—ready for us to start adding chat functionality in the episodes to come!