2017-05-04 30 views
0

我有三个表如何从三个连接表返回数组Laravel 5

- Patients 
- Medicines 
- Services 
- Patient_medicines 
- Patients_services 

我已经离开加入了他们,并得到下面的结果

firstname : Nassoro, 
lastname : Hamisi 
Medicines : Dou Cotexin 
Services : See a Doctor 

firstname : Nassoro, 
lastname : Hamisi 
Medicines : Dou Cotexin 
Services : TEST UTI 

firstname : Nassoro, 
lastname : Hamisi 
Medicines : Malaphin 
Services : See A doctor 

firstname : Nassoro, 
lastname : Hamisi 
Medicines : Malaphin 
Services : TEST UTI 

但我想阵列

firstname : Nassoro 
lastname : Hamisi 
Medicines :{'Malaphon' , 'Duo Cotexin'} 
Services : {'See a Doctor' , 'TEST UTI'} 

我正在使用Laravel

+0

我认为你可以使用GROUPBY子句与您的左连接查询 –

+0

您必须为服务列编写子查询 –

回答

2

你可以编码你的结果得到的输出作为一个变量提到

存储你的结果,并通过它来进行编码方法

json_encode($variable); 

希望它会为你工作