I'm retreiving data from severel tables in the following way:
$data = Accommodation::join("hotels", "accommodations.hotel_id", "=", "hotels.id")
->join("room_types", "accommodations.room_type", "=", "room_types.id")
->join("country", "accommodations.country_id", "=", "country.id")
->join("accommodation_accreditation", "accommodations.id", "=", "accommodation_accreditation.accommodation_id")
->join("accreditation", 'accreditation.id', "=", "accommodation_accreditation.accreditation_id")
->select('hotels.name as Hotel' ,'room_types.type as Room', 'price_per_night as Price per Night', 'check_in as Check In', 'check_out as Check Out', 'nights as Nights', 'sub_total as Sub Total', 'country.name as Country', 'accreditation.full_name as Occupants')
->get()->toArray();
And I receive a row for each occupant in a room.
Room Price per Night Check In Check Out Nights Sub Total Country Occupants
---------------------- ----------------- ------------ ------------ -------- ----------- --------- -------------------
Twin/Double standart 160 2019-04-10 2019-04-15 5 800 UKR Vlad Timochenko
Twin/Double standart 160 2019-04-10 2019-04-15 5 800 UKR Selena Viachenko
I need to concatinate names of occupants and get them in one row like this:
Room Price per Night Check In Check Out Nights Sub Total Country Occupants
---------------------- ----------------- ------------ ------------ -------- ----------- --------- ------------------------------------
Twin/Double standart 160 2019-04-10 2019-04-15 5 800 UKR Vlada Nikolchenko, Olena Diachenko
Here is my schema for the tables in question
Hope it's clear. Will be greatfull if you could help.