Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sarmadindhar's avatar

Help in building eloquent relationships

Hi all. I have a system that provides services like plumber , carpenter , electrician to the customers. The system will be used by three people Customers, Companies, Technicians. The company will provide certain services like AC repair , plumber, carpenter etc The technician will select a particular company at the time of signup and will select one or more services(in which technician is specialized) that the company provides. And finally the customer will add a service request/job within specific service(Like Ac repair request) that will be accepted by any of technicians that are available for that service.And the technician will go to the address provided by customer and fix the problem.

I am much confused how to design the relations in such a way that required data can be accessed easily. Here are some of basic tables

customers(name,address,phone)

companies(name,registration_code,address,type)

technicians(name,education,experience)

services(id,name)

company_service(id,company_id,service_id)

technician_service(id,technician_id,service_id)

jobs(id,customer_id,service_id,title,description,status)

technician_job(id,job_id,technician_id)

I want to make the relations in such a way that if I can access the technicians of specific company, services provided by specific company, services provided by a technician, jobs completed by a technician, j etc etc.

0 likes
1 reply
burlresearch's avatar

This is a big ask - b/c so many moving parts. I'd suggest to

  1. build what you want incrementally, one or two models at a time
  2. focus initially on the links between the models (rather than the properties of the models, this is just additional typing)
  3. test the relationships - then think of expanding to the next model

It's good that you have an overall picture of what you want. But as you build it you will run into little things that will tweak how you round out the schema relations.

Likely I'd start with a Technician model (since that looks central to you) and work out from there.

(I've actually built a Laravel site that essentially does almost the same thing as what you describe.)

From a Laravel command line, I'd say start building the relationships between the core models of your schema:

scott@kudu:/srv/trades$ artisan make:model -a -- Technician
Model created successfully.
Created Migration: 2019_01_19_034657_create_technicians_table
Controller created successfully.
scott@kudu:/srv/trades$ artisan make:model -a -- Company
Model created successfully.
Created Migration: 2019_01_19_034705_create_companies_table
Controller created successfully.
scott@kudu:/srv/trades$ artisan make:model -a -- Customer
Model created successfully.
Created Migration: 2019_01_19_034723_create_customers_table
Controller created successfully.
scott@kudu:/srv/trades$ artisan make:model -a -- Service
Model created successfully.
Created Migration: 2019_01_19_034807_create_services_table
Controller created successfully.
scott@kudu:/srv/trades$ 

Please or to participate in this conversation.