php – Laravel distinct query and object to array conversion is not working-ThrowExceptions

Exception or error:

I want to show unique location names and ids and also i want it as array, if i didint use groupBy it will works and showing data as object. My requiremnt is to retrive it as unique array and its not working.
I dont know what is the error in code

public function showClinicLocations($id)
        $clinic = Clinic::find($id);
        $locations = Location::where('clinicID', $id)->get();
        $locationservices = Service::select('services.serviceName as servicename','locations.locationID as locid','locations.locationName as locname') 
        ->join('location_services', 'location_services.serviceID', '=', 'services.serviceID')
        ->join('locations', 'locations.locationID', '=', 'location_services.locationID') 
        ->join('clinics', 'clinics.clinicID', '=', 'locations.clinicID') 

        echo $locationservices;

       // $locationservices = json_encode(array_unique($locationservices));

        return view('clinic.locations')->with(['locations' =>  $locations  ,'clinic'=>$clinic , 'services'=> $locationservices]);

Can you please help me

I have uploaded outputenter image description here

If there is multiple same loc id only one loc id should be shown

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *