I have a ManyToMany relation
Users controller
public function measurement()
{
return $this->belongsToMany('Measurement', 'users_measurement')->withPivot('value');
}
Column structure
user_id | measurement_id | value
->whereHas('measurement', function($q) use ( $from, $to )
{
foreach (array_combine($from, $to) as $f => $t) {
if(!empty($f) && !empty($t))
{
$q->whereRaw('( users_measurement.value between ? and ?)', array($f, $t));
}
}
})
Error
(select count(*) from `lara_measurements` inner join `lara_users_measurement` on `lara_measurements`.`id` = `lara_users_measurement`.`measurement_id` where `lara_users_measurement`.`user_id` = `lara_users`.`id` and ( users_measurement.value between 154 cm and 168 cm) and ( users_measurement.value between 47 kg and 53 kg))
if i use
$q->whereRaw('( mesurement_id between ? and ?)', array($f, $t));
works
if i use
$q->whereRaw('( user_id between ? and ?)', array($f, $t));
works again
Made these just for a test, but why does it not working with value column ?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community