Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
laravel/php-按id分组,但仍然可以获得每行数据_Php_Mysql_Laravel 5 - Fatal编程技术网

laravel/php-按id分组,但仍然可以获得每行数据

laravel/php-按id分组,但仍然可以获得每行数据,php,mysql,laravel-5,Php,Mysql,Laravel 5,这是我的桌子 patient_id | vaccine_id 7 2 7 3 我希望它在我的html上像这样显示 患者编号:7,疫苗编号:2,3 我的控制器上有此查询 return App\Notification::join('patients', 'patients.PatientID', '=', 'notifications.patient_id') ->

这是我的桌子

 patient_id  |  vaccine_id
     7              2
     7              3
我希望它在我的html上像这样显示

患者编号:7,疫苗编号:2,3

我的控制器上有此查询

return App\Notification::join('patients', 'patients.PatientID', '=', 'notifications.patient_id')
                        ->join('parent_accounts', 'parent_accounts.ParentID', '=', 'patients.parent_id')
                        ->join('vaccines', 'vaccines.VaccineID', '=', 'notifications.vaccine_id')
                        ->select('parent_accounts.parent_phonenumber','patients.*','vaccines.vaccine_name')
                        ->where('due_date', $request->due_date)->get();
但它正在展示

patient id: 7, vaccine id: 2 , patient id: 7, vaccine id: 3
我试过使用
groupby('patient_id')

但它是这样显示的患者id:7,疫苗id:2
它不显示其他疫苗id

您必须将
组(疫苗id)
groupby('patient\u id')
一起使用才能获得所需的格式,如:

->selectRaw('GROUP_CONCAT(vaccine_id)')

使用组_concat()听起来很棒!!