In this episode, we kick things off by setting up our employees and services—basically, who works in our system and what services they can perform. First, we create the Employee model, its migration, and a factory for testing. The employee table is simple for now—just a name, a unique slug for clean URLs, and a profile photo URL. We run our migration, add a couple of sample employees (even if we don’t have all the profile photos yet), and confirm our setup works.
Next, we move on to the Service model, with its migration and factory. Services will just have a title, slug, duration (in minutes), and price (stored as cents/pence for accuracy). We add a few example services—like "hair" and "beard"—and get those into our database.
After that, we need a way to connect which employees can perform which services. For this, we use a classic pivot table setup in Laravel called employee_service
. It's as simple as having foreign keys for both the employee and the service. Once set up, we fill this out manually for some quick testing, mapping, for example, Alex to both "hair" and "beard" services, while Mabel is just assigned "hair."
With data in place, we hop into our models and set up the belongsToMany
relationships so we can easily query which services an employee can do, or which employees are available for a service. A quick test in the browser confirms this works: we can see exactly which services each employee offers.
To round things off, we tweak the factories for both employees and services to give us realistic fake data for testing in the future. That way, we’re ready for automated tests and can easily generate the data we need.
So by the end of this episode, we have the core data structure for employees and services all set up and connected, ready to build on top of!