Beispiel #1
0
 public function anyData(Request $req)
 {
     // $data = Dokumens::all();
     // $count = App\Flight::where('active', 1)->count();
     // $data = \DB::table('dokumen');
     // $data = Dokumens::with('jenissppd');
     $data = Dokumens::with('penerima', 'skpd', 'unitkerja', 'jenissppd', 'file', 'user');
     // $data = Dokumens::with('penerima','skpd');
     // dd($data->get());
     /*pencarian data ===============================*/
     if ($req->get('cari')) {
         $i = 0;
         foreach ($this->caris as $key => $cari) {
             $get = $cari . '_ck';
             //echo $get;
             // var_dump($req->get($get));
             // var_dump($req->get($cari.'_ck'));
             if ($req->get($get) == 'on') {
                 $mystring = $req->get($cari);
                 $findme = '*';
                 $query = strpos($mystring, $findme) === false ? $req->get($cari) . '%' : str_replace('*', '%', $req->get($cari));
                 if ($i == 0 or $cari == 'skpd_id' or $cari == 'jenis_sppd_id' or $cari == 'penerima_id') {
                     $query = $req->get($cari);
                     $data->where($cari, '=', $query);
                     $i++;
                 } elseif ($i == 0) {
                     $data->where($cari, 'like', $query);
                     $i++;
                 } elseif ($i !== 0) {
                     // $data->orWhere($cari,'like',$req->get($cari).'%');
                     $data->orWhere($cari, 'like', $query);
                 }
             }
         }
         return $this->show_relasi_kolom($data->get());
     }
     /* paging biasa ======================================   select * from `dokumen` limit 0,10  */
     if ($req->get('page')) {
         // dd($req->get('page')-1);
         if ($req->get('page') == 1) {
             $offset = $req->get('page') - 1;
         } else {
             $offset = ($req->get('page') - 1) * $req->get('rows');
         }
         $data->skip($offset);
     }
     if ($req->get('rows')) {
         $data->take($req->get('rows'));
     }
     if ($req->get('sort') && $req->get('order')) {
         $data->orderBy($req->get('sort'), $req->get('order'));
     }
     // dd($data->get());
     $datax['rows'] = $this->show_relasi_kolom($data->get());
     $total['total'] = \DB::table('dokumen')->count();
     // dd($data->get());
     return $total + $datax + ['token' => csrf_token()];
     //
 }