taufikmas

CustomPageController.php

Oct 3rd, 2018
165
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!--INI FILE CONTROLLER FOR GMAP LARAVEL -->
  2. <?php
  3.  
  4. namespace App\Http\Controllers;
  5.  
  6. use Illuminate\Http\Request;
  7. use DB;
  8.  
  9. class CustomPageController extends Controller
  10. {
  11.     //
  12.  
  13.     public function peta(Request $req){
  14.         $input = $req->all();
  15.         if($input){
  16.             $all_data = $this->loadAllData($input);
  17.         }
  18.         else{
  19.             $all_data = $this->loadAllData(null);  
  20.         }
  21.         $all_indikator = $this->getAllIndikator();
  22.         $user = DB::table('cms_users')->select('id','name')->where('id_cms_privileges',3)->get();
  23.         return view('custom.peta.index',compact('all_indikator','all_data','user'));
  24.     }
  25.  
  26.  
  27.     public function getAllIndikator(){
  28.         // group per indikator
  29.         $find_ind = DB::table('master_all_indikator')->select(DB::raw("distinct(indikator)"))->get();
  30.         foreach ($find_ind as $key => $value) {
  31.             $hasil[$value->indikator] = $this->getIndikator($value->indikator);
  32.         }
  33.         return $hasil;
  34.     }
  35.  
  36.     public function getIndikator($indikator){
  37.         return DB::table('master_all_indikator')->select('indikator','title','value','text')->where('indikator',$indikator)->orderBy('value')->get();
  38.     }
  39.  
  40.     public function loadAllData($filtered = null){
  41.         $data = DB::table('peoples as p')->select('*')->join('cms_users as u','u.id','=','p.user_id')->where('u.id_cms_privileges','3');
  42.         if($filtered){
  43.             foreach ($filtered as $key => $value) {
  44.                 if($value!==''){
  45.                     $data = $data->where($key,$value);
  46.                 }
  47.  
  48.             }
  49.         }
  50.  
  51.         // total data
  52.  
  53.         // dd($data->count());
  54.         return $data->get();
  55.     }
  56. }
RAW Paste Data