I have what appears on the face of it to be a simple requirement - search for all Profiles that have a location equal to $locationId and have a specific service ($serviceId), but I'm not sure how to add a where condition that queries via a pivot table?
My models are as follows:
class Profile extends Model {
public function services() {
return $this->belongsToMany('Service', 'profile_services', 'profile_id', 'service_id');
}
}
class Service extends Model {}
What I want to do is something along the lines of this:
$results = Profile::where('location_id', '=', $locationId)->where('services.id', '=', $serviceId)->get();
Note I'm aware that ->where('services.id', '=', $serviceId)
is incorrect (I've put it here to better explain what I'm trying to achieve) but I'd like to know I'd do this using either Eloquent or the DB query builder.