I'm new to CakePHP and I would like to query locations in my DB depending on Google Maps Lat & Lng. How can I add the two andWhere
statements only, if $params['bounds']
is true?
$params = [
'bounds' => 1,
'swLat' => ...,
'swLng' => ...,
'neLat' => ...,
'neLng' => ...
];
$locations = $this->Locations
->find()
->select(['id', 'name', 'lat', 'lng'])
->where(['live' => 1])
->andWhere(function ($exp, $q) {
return $exp->between('lat', $params['swLat'], $params['neLat']);
})
->andWhere(function ($exp, $q) {
return $exp->between('lng', $params['swLng'], $params['neLng']);
})
->order(['name' => 'ASC']);