mirror of
https://github.com/danielbrendel/hortusfox-web.git
synced 2026-05-08 14:49:41 -05:00
#339 Include plants in list
This commit is contained in:
+12
-2
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user