diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 6651154..5dafe10 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -116,23 +116,23 @@ class PresenceController extends Controller ->whereDate("ma.end_date", ">=", $params->clock_time) ->get(); $temp = []; - foreach($geom as $dataGeom){ - $valGeom = json_decode($dataGeom->geom); - if($params->type=="out"){ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), ST_GeomFromText('POINT(".$params->clock_out_lng." ".$params->clock_out_lat.")', 4326)) as boundary")); - }else{ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_lng." ".$params->clock_in_lat.")', 4326)) as boundary")); - } - foreach ($check as $key) { - if($key->boundary){ - $temp[]=array( - "activity_id" => $dataGeom->id, - "boundary" => $key->boundary - ); - } + if (count($geom) > 0) { + foreach($geom as $dataGeom){ + $valGeom = json_decode($dataGeom->geom); + if($params->type=="out"){ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), ST_GeomFromText('POINT(".$params->clock_out_lng." ".$params->clock_out_lat.")', 4326)) as boundary")); + }else{ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_lng." ".$params->clock_in_lat.")', 4326)) as boundary")); + } + foreach ($check as $key) { + if($key->boundary){ + $temp[]=array( + "activity_id" => $dataGeom->id, + "boundary" => $key->boundary + ); + } + } } - - } return $temp; }