i'm trying to get all measurements from a certain recorder between a certain timespan.
If i remove the "->wherebetween()" part of the query and view the results then I get all the sensors of that recorder and all related measurements of that sensor.
But I'm not able to execute a wherebetween on the relation.
query in the controller
public function getChart(Request $request) {
$sensorCollection = Sensor::where('recorder_id', $request->recorder_id)
->with('getMeasurementsRelation')
->wherebetween('getMeasurementsRelation', function ($query) use ($request) {
return $query->wherebetween('timestamp',[$request->start_chart, $request->end_chart]);})
->get();
}
Relationship in Sensor model
public function getMeasurementsRelation() {
return $this->hasmany('App\Models\measurement', 'sensor_id', 'id');}