Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function json($table)
- {
- if ($table != 'kecamatan') {
- $layer = Layer::where('name', $table)->firstOrFail();
- }
- $alist = 'id';
- if (in_array($table, ['bangunan', 'daerah_irigasi', 'eksisting_di', 'saluran', 'titik_kerusakan'])) {
- $alist = implode(',', json_decode($layer->info));
- }
- // Cache::flush();
- if (Cache::has($table)) {
- $result = Cache::get($table);
- } else {
- $result = DB::select("SELECT row_to_json(fc) AS geojson FROM ( SELECT 'FeatureCollection' AS type, array_to_json(array_agg(f)) AS features FROM ( SELECT 'Feature' AS type, ST_AsGeoJSON(lg.geom)::json AS geometry, row_to_json(( SELECT l FROM (SELECT $alist) AS l )) AS properties FROM $table AS lg ) AS f ) AS fc");
- Cache::forever($table, $result);
- }
- return response($result[0]->geojson)->header('Content-Type', 'application/json');
- }
Advertisement
Add Comment
Please, Sign In to add comment