#339 Include plants in list

This commit is contained in:
Daniel Brendel
2025-02-15 15:40:05 +01:00
parent 4ae0d8aa1f
commit ae0b2ed0fe
+12 -2
View File
@@ -499,12 +499,22 @@ class ApiController extends BaseController {
{
try {
$only_active = $request->params()->query('only_active', false);
$include_plants = $request->params()->query('include_plants', false);
$data = LocationsModel::getAll($only_active);
$locations = LocationsModel::getAll($only_active)?->asArray();
if (($locations) && ($include_plants)) {
foreach ($locations as $key => $location) {
$cur_plants = PlantsModel::getAll($location['id'])?->asArray();
$locations[$key]['plant_count'] = count($cur_plants);
$locations[$key]['plant_list'] = $cur_plants;
}
}
return json([
'code' => 200,
'list' => $data?->asArray()
'list' => $locations
]);
} catch (\Exception $e) {
return json([