/** * Display a listing of the resource. * * @return Response */ public function withinBounds(Request $request) { //TODO: Validate (regex validation to bounds) // // parse bounds $coordinates = explode(", ", $request->bounds); $sw_lat = $coordinates[2]; $sw_lng = $coordinates[3]; $ne_lat = $coordinates[0]; $ne_lng = $coordinates[1]; $trashes = DB::select(' SELECT * FROM trashes WHERE trashes.geom && ST_MakeEnvelope(?, ?, ?, ?)', [$sw_lat, $sw_lng, $ne_lat, $ne_lng]); //get id's of the trashes $trash_ids = []; foreach ($trashes as $trash) { $trash_ids[] = $trash->id; } $trashes = Trash::whereIn('id', $trash_ids)->get(); $trashesArray = []; foreach ($trashes as $trash) { $array = $trash->toArray(); $array['types'] = $trash->types->pluck('type')->toArray(); $trashesArray[] = $array; } $trashes = collect($trashesArray); return $trashes; }
public function trashesInsideTile() { $trashes = DB::select(' SELECT * FROM trashes WHERE trashes.geom && ST_MakeEnvelope(?, ?, ?, ?)', [$this->sw_lat, $this->sw_lng, $this->ne_lat, $this->ne_lng]); //get id's of the trashes $trash_ids = []; foreach ($trashes as $trash) { $trash_ids[] = $trash->id; } $trashes = Trash::whereIn('id', $trash_ids)->get(); return $trashes; }