我有三个表呼叫用户,服务,类别和数据透视表呼叫专业人员。 还有所有表的四个模型。
User: Id, name
Services: id, service_name
Categories: id, service_id, category_name
Professionals: id, user_id, service_id, category_id
Relationships
User has many Categories
Service has many categories
category can have one service
category belongs to many users
$result = Professional::where('user_id’,’=‘,54)->get();
以上命令给出如下数据:
{
"id": 1,
"user_id": 54,
"service_id": 8,
"category_id": 20
},
{
"id": 2,
"user_id": 54,
"service_id": 10,
"category_id": 23
},
{
"id": 3,
"user_id": 54,
"service_id": 9,
"category_id": 21
},
{
"id": 4,
"user_id": 54,
"service_id": 10,
"category_id": 22
}
请帮助我从“专家”表中获取与用户相关的类别和服务详细信息的数据,指导我如何在模型上建立关系