I have two tables clinic
and service
. In service
table there is a column clinic_id
. Now I want to retrieve all the services under every column.
I am giving some demo data for better understand.
clinic table data
{id:1,name:clinic1},{id:2,name: clinic2}
service table data
{id: 1, clinic_id: 1, name: service11},
{id: 2, clinic_id: 1, name: service12},
{id: 3, clinic_id: 2, name: service21},
{id: 4, clinic_id: 2, name: service22}
Now I want to retrieve data like below
{clinic_name: clinic1}:[{service_name: service11}, {service_name: service12}],
{clinic_name: clinic2}:[{service_name: service21}, {service_name: service22}]
What is the SQL query for Laravel ?