hanreev

cache

Jun 3rd, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1.     public function json($table)
  2.     {
  3.         if ($table != 'kecamatan') {
  4.             $layer = Layer::where('name', $table)->firstOrFail();
  5.         }
  6.  
  7.         $alist = 'id';
  8.  
  9.         if (in_array($table, ['bangunan', 'daerah_irigasi', 'eksisting_di', 'saluran', 'titik_kerusakan'])) {
  10.             $alist = implode(',', json_decode($layer->info));
  11.         }
  12.  
  13.         // Cache::flush();
  14.  
  15.         if (Cache::has($table)) {
  16.             $result = Cache::get($table);
  17.         } else {
  18.             $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");
  19.             Cache::forever($table, $result);
  20.         }
  21.  
  22.         return response($result[0]->geojson)->header('Content-Type', 'application/json');
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment