Skip to content
Advertisement

Laravel Join query is not working for 4 tables

I have 4 tables

Table Name : Clinics

Fields: clinicID , clinicName

Table Name : locations

Fileds: locationID, clinicID,locationname

Table Name : Services

Fields: ServiceId , ServiceName

Table Name: LocationServices

Fields: locationServiceID, locationID , ServiceId

My requiremnt is that when i pass clinicID, i need to retrive Corresponding clinics service name, there may be more than one.

But when i tried join query is not working Following is my code in controller

JavaScript

Advertisement

Answer

You can get this details by using relationships. In the Clinic model,add

JavaScript

In the Locations model,add,

JavaScript

On the LocationServices model,

JavaScript

You can get the result by,

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement